I am using Ubuntu 14.04 and running go-ethereum in it. In the ~/.ethash/ folder, I see that there are two DAG files created when mining begins. The first one is created immediately after mining starts and the second one after some time.I am interested in knowing the reason for it.
Every 30,000 blocks - where 30,000 blocks is called an epoch - a new DAG file is generated. This mechanism provides the Ethash algorithm something fresh to work on.
At the end of 30,000 blocks, clients want to switch from their current DAG to the next one as quickly as possible. To this end, the next DAG file is generated in advance.
From the documentation:
Ethash PoW is memory hard, making it basically ASIC resistant. This basically means that calculating the PoW requires choosing subsets of a fixed resource dependent on the nonce and block header. This resource (a few gigabyte size data) is called a DAG. The DAG is totally different every 30000 blocks (a 100 hour window, called an epoch) and takes a while to generate. Since the DAG only depends on block height, it can be pregenerated but if its not, the client need to wait the end of this process to produce a block.
If you want to prevent the pregeneration (I can't see why you would, but it's your network... ), then you can do so on the command line.