Recently it was discovered that twisted superconformal index I can be used to understand the Bekenstein-Hawking entropy of magnetically charged black holes in AdS spacetime. In this paper we apply the so-called I-extremization procedure to threedimensional gauge field theories and their geometric dual, focusing in particular on the seven-dimensional Sasaki-Einstein manifold M 1,1,1 . We generalize recent studies on relations among toric geometry, variational principles, and black hole entropy to the case of AdS 2 × Y 9 , where Y 9 is a fibration of toric Sasaki-Einstein manifold M 1,1,1 over a twodimensional Riemann surface Σ g . The nine-dimensional variational problem is given in terms of an entropy functional. In order to illustrate the computations as explicitly as possible, we consider cases where either only mesonic or baryonic fluxes are turned on. By employing the operator counting method, we calculate the S 3 free energy and the topologically twisted index I at large-N . The result for I, it turns out, can be also obtained from the variational principle of the entropy functional with mesonic fluxes. We also study asymptotically AdS 4 black holes which are magnetically charged with respect to the vector field in the Betti multiplet. By extremizing the entropy functional with baryonic flux, we compute the entropy and find that it agrees with the entropy of an explicit solution in a four-dimensional gauged supergravity which is a consistent truncation of eleven-dimensional supergravity in AdS 4 × M 1,1,1 . arXiv:1904.05344v2 [hep-th]