kref_put(&h->ref, cd->cache_put);
 }
 
+static inline int cache_valid(struct cache_head *h)
+{
+       /* If an item has been unhashed pending removal when
+        * the refcount drops to 0, the expiry_time will be
+        * set to 0.  We don't want to consider such items
+        * valid in this context even though CACHE_VALID is
+        * set.
+        */
+       return (h->expiry_time != 0 && test_bit(CACHE_VALID, &h->flags));
+}
+
 extern int cache_check(struct cache_detail *detail,
                       struct cache_head *h, struct cache_req *rqstp);
 extern void cache_flush(void);
 
 #include <linux/seq_file.h>
 #include <linux/hash.h>
 #include <linux/string.h>
+#include <net/sock.h>
 
 #define RPCDBG_FACILITY        RPCDBG_AUTH
 
        cache_purge(&ip_map_cache);
 }
 
+static inline struct ip_map *
+ip_map_cached_get(struct svc_rqst *rqstp)
+{
+       struct ip_map *ipm = rqstp->rq_sock->sk_info_authunix;
+       if (ipm != NULL) {
+               if (!cache_valid(&ipm->h)) {
+                       /*
+                        * The entry has been invalidated since it was
+                        * remembered, e.g. by a second mount from the
+                        * same IP address.
+                        */
+                       rqstp->rq_sock->sk_info_authunix = NULL;
+                       cache_put(&ipm->h, &ip_map_cache);
+                       return NULL;
+               }
+               cache_get(&ipm->h);
+       }
+       return ipm;
+}
+
+static inline void
+ip_map_cached_put(struct svc_rqst *rqstp, struct ip_map *ipm)
+{
+       struct svc_sock *svsk = rqstp->rq_sock;
+
+       if (svsk->sk_sock->type == SOCK_STREAM && svsk->sk_info_authunix == NULL)
+               svsk->sk_info_authunix = ipm;   /* newly cached, keep the reference */
+       else
+               cache_put(&ipm->h, &ip_map_cache);
+}
+
+void
+svcauth_unix_info_release(void *info)
+{
+       struct ip_map *ipm = info;
+       cache_put(&ipm->h, &ip_map_cache);
+}
+
 static int
 svcauth_unix_set_client(struct svc_rqst *rqstp)
 {
        if (rqstp->rq_proc == 0)
                return SVC_OK;
 
-       ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class,
-                           rqstp->rq_addr.sin_addr);
+       ipm = ip_map_cached_get(rqstp);
+       if (ipm == NULL)
+               ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class,
+                                   rqstp->rq_addr.sin_addr);
 
        if (ipm == NULL)
                return SVC_DENIED;
                case 0:
                        rqstp->rq_client = &ipm->m_client->h;
                        kref_get(&rqstp->rq_client->ref);
-                       cache_put(&ipm->h, &ip_map_cache);
+                       ip_map_cached_put(rqstp, ipm);
                        break;
        }
        return SVC_OK;