Is confession valid if the penitent doesn’t remember how many times he committed a mortal sin?
Yes, it is valid. The penitent simply needs to be honest and sincere and repentant. The penitent can give a “round number” of the times the sin was committed or perhaps approximately how long the sin has persisted.
The Baltimore Catechism:
Q. 792. What should we do if we cannot remember the number of our sins?
A. If we cannot remember the number of our sins, we should tell the number as nearly as possible, and say how often we may have sinned in a day, a week, or a month, and how long the habit or practice has lasted.