Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753382AbdDJUWu (ORCPT ); Mon, 10 Apr 2017 16:22:50 -0400 Received: from mx141.netapp.com ([216.240.21.12]:15581 "EHLO mx141.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751712AbdDJUWs (ORCPT ); Mon, 10 Apr 2017 16:22:48 -0400 X-IronPort-AV: E=Sophos;i="5.37,182,1488873600"; d="scan'208";a="195053909" Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=Netapp.com; Subject: Re: [PATCH] NFS: fix usage of mempools. To: NeilBrown , Trond Myklebust References: <87wpatvw6m.fsf@notabene.neil.brown.name> CC: , From: Anna Schumaker Message-ID: <586583e7-58d4-2386-aa71-f0a63ca93002@Netapp.com> Date: Mon, 10 Apr 2017 16:22:39 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <87wpatvw6m.fsf@notabene.neil.brown.name> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [68.40.188.1] X-ClientProxiedBy: MWHPR07CA0029.namprd07.prod.outlook.com (10.169.230.15) To BN6PR06MB2466.namprd06.prod.outlook.com (10.173.22.7) X-MS-Office365-Filtering-Correlation-Id: 530cddfa-5c82-4655-1c7a-08d4804f595a X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:BN6PR06MB2466; X-Microsoft-Exchange-Diagnostics: 1;BN6PR06MB2466;3:09nEDw4k3b776UQJARMjpzWXD1ZDTHIsTJZqcojKHY9t3Ldbsnhr5jAiZbeVzFoei0Hy34uWOP6Z6S+Sgm23UzTwv5QYHqPgbkhTbDhJLgbMcaz2Kqhg11nVb4OeVXr04/DFz/Nm7CHCF3Wwf85aKrMV5y+Bzo4g0hBZOvJDLvzo8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tzDc7KP+wxm/n26SbrEI7azf1oS+kr2IeV9qaxSXKMyob+UCMmATEZHZ/SEFrmC4W1JifYpDQXPA7DgZc6xIuk9Spi1iZHREq2oI0ecF1MaEeHWDv4LAEXEkPGKhvuI459PbJw329+mNs3wMe1bSouyA/MCgi/vv9RKkS4l8wXTNOUn0/Jx+q1Z587SpxA4d70EF+q643yJiVjpQtv/Ftk0xkHShW9qRoTHgD5qJ9lNua8RydEEeBwwS8zlI43FNzwyvTPBNUxtHpFqe4oOvHsRxSWv36VR4Jq7DCHkc5iQ+3iUJ4mLQ8ndn4X0bn1XiVvbXqPjOYpbRbf1MQVFI9qLdqW27TIhNofa1Z3yyih2KphaqaEonJnC1knmm0eKJUeUn0rK5g9lLwulIFRB1kfanvzwOb6om9KS3sb X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041248)(20161123564025)(20161123560025)(20161123562025)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(6072148);SRVR:BN6PR06MB2466;BCL:0;PCL:0;RULEID:;SRVR:BN6PR06MB2466; X-Microsoft-Exchange-Diagnostics: 1;BN6PR06MB2466;4:ZuEguxZ7L4MWuLxkSW/IVPsMb9I5fvEFo7Jun751qbfdmQ8ffjmsNEvEmMKnovqP/ieMg7eGSxpw0BMp8E8wmZpAV6kGZvFsMuo2sZTGIbD3g5J6BaP254ywmWZcpRASEkLTJPn/P07aJqIHS1Q7ExClbfPrYR6IRH2wwcrIs9tutCAJuUHOLqsWWHzFinRDFAKrtK883I+88MYdSgJuU89pZ7DDY+ArpGC8LVMd5sR2/EGyn5FfmhXukBLkoRTxJiJ/xaMW67SqrfYfeHkd8uu5gPugOs5/7vobE5JKXvLcUQIQ4DGHePznWAcxypX/SDhFmXrN63I7Hb4XlIbss6J97czg/WTGnvkJfZ4J21rOQjmShts/3wA/bAhO0gX3NgzfPjD+SLoNQtCVB0DH/k5Aj4mKtLWKmqTtIDuIG1QfPsrac9Aw6MyWZ0HbeXHMCLPIkGQHyIdP3uFgme/OuPz4ciQYFoag2ZQU3DgWNMMava1Qq9VOS6wk1Cy1zmis6FjiZ20bEZQJv0Yxdl2qaKv3vqU00bWzumTczl+ExOgk38sjZCpJWM+b6GDkfpm8H8wMjCbzwLJ+czCFGrsB6nqakAjkBzdEWtKmv7smwgDgqmqHju8Sfbn8kPdOe/U25p1KoNAo1obvUO5u+yjhL4oGtQgQSvSjsesKpComnJNxT27REj/H5j6Pn+HsmBu5VZj2F15viEYPm1cXPX3gY47kiVKuRP5BsQXquol75h4= X-Forefront-PRVS: 027367F73D X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39410400002)(39400400002)(39450400003)(39840400002)(377454003)(57704003)(24454002)(31686004)(42186005)(6666003)(50466002)(53416004)(8676002)(65826007)(4326008)(64126003)(7736002)(6506006)(305945005)(33646002)(6486002)(230700001)(66066001)(4001350100001)(5660300001)(229853002)(2906002)(81166006)(25786009)(2950100002)(53546009)(65956001)(38730400002)(86362001)(31696002)(6116002)(3846002)(47776003)(54356999)(36756003)(54906002)(53936002)(76176999)(23746002)(50986999)(6512007)(83506001)(189998001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR06MB2466;H:gouda.nowheycreamery.com;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;BN6PR06MB2466;23:+mRIdsHjuB5j5h6JdgZKh7n4GUnAN5e+98VDo?= =?Windows-1252?Q?zob2V92JaGEKtuqIUixJ0VhfwCzBGtX8HRY0z1ZYoKoeNHCT6FFJ7qEX?= =?Windows-1252?Q?6UT1tk4zTjYAeb7gNB3IwvYYoG+NWWbMN5WaHIXHZVEwRPmyp6aFbwV5?= =?Windows-1252?Q?bPY7/Ic0OgVEiTk1PciXQoZEAnrcoYL62XSRmVHF9ATH6g0StpgVAIgi?= =?Windows-1252?Q?jZ8bOk4qTA0YLpwUtDp/6f3VY6OzKef5vvi1sS4h0+AWH6lnlp0MvlIc?= =?Windows-1252?Q?2dJYoINirVT6CBAq8Cmr89E6Radsb5rWOi9q3BQ2KhOUqusuLCzMEn/f?= =?Windows-1252?Q?yl1Dbe6G4qNJJgfu76gbkZHKrMjrIkKf20joreumNIObBjEFCbnIltuZ?= =?Windows-1252?Q?/7HcPcMQyL+JRGXLhG1yrdkYq6oa13SYFkSCJ7BjMHI9RahHiWvIB30Q?= =?Windows-1252?Q?2aD4Y7iDvg2lbXD7XGmEuQaSQspxsIoP+6sZg+w1+OkTUDskyyfyyRKt?= =?Windows-1252?Q?bzO26OzuHOJcvKe0gMVzqL24aCvHzm6Itq0gYOlSoHwgSXTJ71V7nIt8?= =?Windows-1252?Q?OfVd7JXrMhzRcvjBv3EMSc44S+OJZgaUbkywmJ+cXujI+kBng10/Zu96?= =?Windows-1252?Q?HDQZbcG97yLqsK3dFM3sEbjdCyuv6Qz7jip8DHtNy22spirWFkqWbDDb?= =?Windows-1252?Q?7MJtAwUKP5ALB0ycWV6jNiqoX6g/Z6LWh0vw0VTKs3lZVDciwIgt2NMb?= =?Windows-1252?Q?876dVBkNG5nk0BR/rUql/abPizbf6CpY1ZL4TMKhaczN6cf7SAYeqFZT?= =?Windows-1252?Q?gdzdstevpQxnMwLNQmuw9EVwQVeHu8AsU+ZI2EC2UoHXpWUy4vwVmpxY?= =?Windows-1252?Q?0qR2JH8TfdQPhiZ2gmG+dof0dB1C/3o258kmU1Bd734lC1uX03zVOJ+4?= =?Windows-1252?Q?r9uVOjUaKXD4g0W1bdMmc1q5cH7iDao+cqmdt88BJdLUUFWYiMZpZBc2?= =?Windows-1252?Q?fqgnKZLF+ZwUxoVBzgNq3scdQqFbUMUuemseuxk/JkFSyW13joYJ148o?= =?Windows-1252?Q?9Erdjzgqh9ykoypUhfvwRs8FtMFETefNfrF4AV5L3+gtg0X014ln+eww?= =?Windows-1252?Q?ZgP7WNfqTBm7wGFGa1F1MqBgGTSpxtqB+KfGulFfI+qoC0CZ5TgP0gC3?= =?Windows-1252?Q?3erHa1DxONRchQNIV8QxJWl4nGbR4/kl+8IBgFcC30YgKoVLdYWg5s5X?= =?Windows-1252?Q?RtFMTpt6eF37Zjq/J6IAgTxgDgxchuSe+e5yZ4zgca7wf4ou6EyUDR8W?= =?Windows-1252?Q?veToPXtvQISby+oRk1rf04mdxl0onikmE87oyM48u5Kg/U=3D?= X-Microsoft-Exchange-Diagnostics: 1;BN6PR06MB2466;6:kw8qcHAQs75qi/OhaTKSkCDhxRoWyQLlvW3YueX2PugpAy5+mEzpNli4pbsyvk37c5EpBI1NN0adeNIt16vZH4EU+5TOHpXSnoLrh+kmDQXzM2qs9unPMj1tlvQxyzeXmwyMeguKg9IyoXH/Z7apMga3wTgrWHNIOEpQIt/jr2nbm4KRGLmc65X9naPL2u3j/DWJE3+3w5fHlfkzHqknPidVi4GZ3HMPGziF5wCX9EnW7rsWcAracqYYsfcCnE6n3OGdTHr203bodoij2JtW36NOCvUfIdqDIpOpsjLUzaZavVA/JEVcud36QgLjwMBpKpaYGy5qLH0/sQ7QnJs0BzhczdxEphYYCDVieSY5FU68pDk8/5BfvpuarRFWl3IIvNmy00NwxtcEgoPoKZ4QjB7Bp1h2C3mbbTconD5Rdzx2eHbcTB6mK/XUBU4hl0J+23AwGY2PjOPkPJyvMejgxQ==;5:OqFlvShLEbWdmv56HA02hopRrGfV91OWOzuZw/bw9ALwRfgN3geCh/kXzc48mxzjYN6kTixyhVNNDCDKA9F5doOoD5XUmhX92lo/5GkB01OLrjGZtMPpwFhquTwq6dxIdA1SWNskgr94x4RHOLm+JJ7U4s4e9jlzi6gijX5ePH8=;24:uLggjjydMScBuq2773MzzYpWAlhog+PN2MWJsN3hiTZD9KB+msJFBxEjiFrSGcTZ8gqztbX8TnDsMEhS5047grkX2AT9cfvBaGUlSonpDRw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR06MB2466;7:v6y2XJSgajXaTqH392+mil7hzE7QlMmkaIUbbNcEl7kxbS8ktFBWtn+fo05VvI6zQlpeRw/sNuxvsNxJqqHKHtyhO3ke88FQhtk9lfDHNo0kn3Tyk6/LNvzIGqy2npdmw3FqoxnhqKQFt7jamU8spZj4rfx5JrbM1WJtstmJbbxn10eIR3zXNptBRYJjniWBiDZm401HxthquG2ylG2lJ3YPo4uBTQvSzJmRHJ2tTrSHV+mvtMDizWvyOSa+dWJ6ae2Su/wPkdWydWW2AjRSMhCBySI8HyR0+Ko98aBj/60HMzq4AIOJ4lAmQ0qXg5+WnKeJrXkqlv/N0PnH+jBGiQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2017 20:22:44.6924 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR06MB2466 X-OriginatorOrg: netapp.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5847 Lines: 168 Hi Neil, On 04/09/2017 10:22 PM, NeilBrown wrote: > > When passed GFP flags that allow sleeping (such as > GFP_NOIO), mempool_alloc() will never return NULL, it will > wait until memory is available. > > This means that we don't need to handle failure, but that we > do need to ensure one thread doesn't call mempool_alloc() > twice on the one pool without queuing or freeing the first > allocation. If multiple threads did this during times of > high memory pressure, the pool could be exhausted and a > deadlock could result. > > pnfs_generic_alloc_ds_commits() attempts to allocate from > the nfs_commit_mempool while already holding an allocation > from that pool. This is not safe. So change > nfs_commitdata_alloc() to take a flag that indicates whether > failure is acceptable. > > In pnfs_generic_alloc_ds_commits(), accept failure and > handle it as we currently do. Else where, do not accept > failure, and do not handle it. > > Even when failure is acceptable, we want to succeed if > possible. That means both > - using an entry from the pool if there is one > - waiting for direct reclaim is there isn't. > > We call mempool_alloc(GFP_NOWAIT) to achieve the first, then > kmem_cache_alloc(GFP_NOIO|__GFP_NORETRY) to achieve the > second. Each of these can fail, but together they do the > best they can without blocking indefinitely. > > Also, don't test for failure when allocating from > nfs_wdata_mempool. > > Signed-off-by: NeilBrown > --- > fs/nfs/pnfs_nfs.c | 16 +++++----------- > fs/nfs/write.c | 35 +++++++++++++++++++++-------------- > include/linux/nfs_fs.h | 2 +- > 3 files changed, 27 insertions(+), 26 deletions(-) > > diff --git a/fs/nfs/pnfs_nfs.c b/fs/nfs/pnfs_nfs.c > index 7250b95549ec..1edf5b84aba5 100644 > --- a/fs/nfs/pnfs_nfs.c > +++ b/fs/nfs/pnfs_nfs.c > @@ -217,7 +217,7 @@ pnfs_generic_alloc_ds_commits(struct nfs_commit_info *cinfo, > for (i = 0; i < fl_cinfo->nbuckets; i++, bucket++) { > if (list_empty(&bucket->committing)) > continue; > - data = nfs_commitdata_alloc(); > + data = nfs_commitdata_alloc(false); > if (!data) > break; > data->ds_commit_index = i; > @@ -283,16 +283,10 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages, > unsigned int nreq = 0; > > if (!list_empty(mds_pages)) { > - data = nfs_commitdata_alloc(); > - if (data != NULL) { > - data->ds_commit_index = -1; > - list_add(&data->pages, &list); > - nreq++; > - } else { > - nfs_retry_commit(mds_pages, NULL, cinfo, 0); > - pnfs_generic_retry_commit(cinfo, 0); > - return -ENOMEM; > - } > + data = nfs_commitdata_alloc(true); > + data->ds_commit_index = -1; > + list_add(&data->pages, &list); > + nreq++; > } > > nreq += pnfs_generic_alloc_ds_commits(cinfo, &list); > diff --git a/fs/nfs/write.c b/fs/nfs/write.c > index abb2c8a3be42..bdfe5a7c5874 100644 > --- a/fs/nfs/write.c > +++ b/fs/nfs/write.c > @@ -60,14 +60,28 @@ static mempool_t *nfs_wdata_mempool; > static struct kmem_cache *nfs_cdata_cachep; > static mempool_t *nfs_commit_mempool; > > -struct nfs_commit_data *nfs_commitdata_alloc(void) > +struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail) > { > - struct nfs_commit_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOIO); > + struct nfs_commit_data *p; > > - if (p) { > - memset(p, 0, sizeof(*p)); > - INIT_LIST_HEAD(&p->pages); > + if (never_fail) > + p = mempool_alloc(nfs_commit_mempool, GFP_NOIO); > + else { > + /* It is OK to do some reclaim, not no safe to wait > + * for anything to be returned to the pool. > + * mempool_alloc() cannot handle that particular combination, > + * so we need two separate attempts. > + */ > + p = mempool_alloc(nfs_commit_mempool, GFP_NOWAIT); > + if (!p) > + p = kmem_cache_alloc(nfs_cdata_cachep, GFP_NOIO | > + __GFP_NOWARN | __GFP_NORETRY); Do we need to add something to the nfs_commit_data structure to properly free a kmem_cache_alloc()-ed object? Right now it looks like nfs_commit_free() calls mempool_free() unconditionally. Thanks, Anna > + if (!p) > + return NULL; > } > + > + memset(p, 0, sizeof(*p)); > + INIT_LIST_HEAD(&p->pages); > return p; > } > EXPORT_SYMBOL_GPL(nfs_commitdata_alloc); > @@ -82,8 +96,7 @@ static struct nfs_pgio_header *nfs_writehdr_alloc(void) > { > struct nfs_pgio_header *p = mempool_alloc(nfs_wdata_mempool, GFP_NOIO); > > - if (p) > - memset(p, 0, sizeof(*p)); > + memset(p, 0, sizeof(*p)); > return p; > } > > @@ -1705,19 +1718,13 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how, > if (list_empty(head)) > return 0; > > - data = nfs_commitdata_alloc(); > - > - if (!data) > - goto out_bad; > + data = nfs_commitdata_alloc(true); > > /* Set up the argument struct */ > nfs_init_commit(data, head, NULL, cinfo); > atomic_inc(&cinfo->mds->rpcs_out); > return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode), > data->mds_ops, how, 0); > - out_bad: > - nfs_retry_commit(head, NULL, cinfo, 0); > - return -ENOMEM; > } > > int nfs_commit_file(struct file *file, struct nfs_write_verifier *verf) > diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h > index 287f34161086..1b29915247b2 100644 > --- a/include/linux/nfs_fs.h > +++ b/include/linux/nfs_fs.h > @@ -502,7 +502,7 @@ extern int nfs_wb_all(struct inode *inode); > extern int nfs_wb_single_page(struct inode *inode, struct page *page, bool launder); > extern int nfs_wb_page_cancel(struct inode *inode, struct page* page); > extern int nfs_commit_inode(struct inode *, int); > -extern struct nfs_commit_data *nfs_commitdata_alloc(void); > +extern struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail); > extern void nfs_commit_free(struct nfs_commit_data *data); > > static inline int >