so bitcoind generates the new 100 addresses at once when the last one of the existing ones is used or it always keeps 100 unused ones in advance?
Neither.
If the wallet is unlocked the wallet will create as many new addresses to refill the pool back to 100 anytime it is less than 100 (default).
If the wallet is locked the wallet will not be able to refill the keypool and the number of addresses in the keypool will decline.
If the keypool has 0 addresses and you call getnewaddress it will fail.
Calling getinfo will show the number of keys remaining in the keypool. Try experimenting with getnewaddress, getinfo, and walletpassphrase so observe how the keypool behaves.
Example:
Wallet has a keypool of 100
Lock Wallet. Keypool = 100
GetNewAddress. Keypool = 99
GetNewAddress. Keypool = 98
GetNewAddress. Keypool = 97
GetNewAddress. Keypool = 96
GetNewAddress. Keypool = 95
UnlockWallet. Keypool = 100
GetNewAddress. Keypool = 100 (generated as soon as used)
GetNewAddress. Keypool = 100
GetNewAddress. Keypool = 100
GetNewAddress. Keypool = 100
GetNewAddress. Keypool = 100
LockWallet. Keypool = 100
GetNewAddress. Keypool = 99
GetNewAddress. Keypool = 98
GetNewAddress. Keypool = 97
...
GetNewAddress. Keypool = 1
GetNewAddress. Keypool = 0
GetNewAddress. FAILURE. No address provided, keypool exhausted.
UnlockWallet. Keypool = 100