Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754576AbcLOWlD (ORCPT ); Thu, 15 Dec 2016 17:41:03 -0500 Received: from us-smtp-delivery-194.mimecast.com ([216.205.24.194]:26024 "EHLO us-smtp-delivery-194.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753508AbcLOWlB (ORCPT ); Thu, 15 Dec 2016 17:41:01 -0500 From: Trond Myklebust To: Benjamin Coddington CC: Alexander Viro , Anna Schumaker , Linux NFS Mailing List , Linux FS-devel Mailing List , Linux Kernel Mailing List Subject: Re: [PATCH] NFS: switch back to ->iterate() Thread-Topic: [PATCH] NFS: switch back to ->iterate() Thread-Index: AQHSUiH279fC256QDUG5KIeCWD1E46EJpFIA Date: Thu, 15 Dec 2016 22:40:56 +0000 Message-ID: References: <0429a1fe130e635337b3103ee5fb1ea4c405fdaf.1481290848.git.bcodding@redhat.com> In-Reply-To: <0429a1fe130e635337b3103ee5fb1ea4c405fdaf.1481290848.git.bcodding@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [68.49.162.121] x-ms-office365-filtering-correlation-id: 27d5e866-8f50-49aa-a58a-08d4253b6f15 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN6PR11MB1569; x-microsoft-exchange-diagnostics: 1;BN6PR11MB1569;7:v06TD3P0S3o576cNldraNG8sweVgNiKKrtI+XCXnt5TGbGz30/7O8XvTkm3z58zoz+J0TrLOqeXWnEDAxHtNgvcf9uYeGFDJzN0O13JfvSH+1MmI/4hG16cl9W/PGOIwGhOmyoXqHLkx1UzEx7GxVvDlAOi5CNZNtWe5RsmsHc5bpK3SCYXJjho8Dt528otGmXHCO0ccl/31CgSX7rzsBX85W1Ne6nOgs9rgcKOKpXIIFjNillidIMxIGEF9Ks4ndLEtz2bhoWsdPVIP6ruwYxjg4baShqtSNw8XMmWj7Ov0XmH3bTG8H3rbPxlQ1ErR0nMqCaUaYFgRU73VxeIrVHw4+yG7I9ZTtU/DNNBFBsKCED0CYJ3T8ub9996fvj/a8vDiyWwDsP56qNWb3SVrismejfUWAmG79DN2IdvqU1MQT1qQ74pHwMfBsB2AZN1Gek+dE8k4yIrB8f0FReeQGg==;20:7wJmmiF3Xh51jz29Qi0mr1TJgRnd49C5qrfUy63fxqBgNKXtfnOTH96T7xT8HbN5940j60i8aMBk8jbmB9V1YhJvB/iDFAScWjSHtou5sBSyJQzicVsrdAVlM/BD8UJ9qItFOh3t7lIM+ONnZhtm2Ix52BeVtO1RvUd/dY7aiAc= x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123564025)(2016111802025)(20161123562025)(20161123560025)(20161123555025)(6072148)(6043046);SRVR:BN6PR11MB1569;BCL:0;PCL:0;RULEID:;SRVR:BN6PR11MB1569; x-forefront-prvs: 0157DEB61B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(7916002)(39410400002)(39830400002)(39450400003)(189002)(199003)(24454002)(106116001)(25786008)(77096006)(106356001)(6916009)(5660300001)(2950100002)(110136003)(105586002)(99286002)(2900100001)(4326007)(7736002)(92566002)(2906002)(305945005)(122556002)(82746002)(102836003)(36756003)(6116002)(6486002)(50986999)(101416001)(54356999)(81156014)(6512006)(86362001)(76176999)(3846002)(3280700002)(189998001)(33656002)(229853002)(97736004)(38730400001)(66066001)(83716003)(6436002)(8936002)(3660700001)(81166006)(8676002)(6506006)(68736007)(104396002);DIR:OUT;SFP:1102;SCL:1;SRVR:BN6PR11MB1569;H:BN6PR11MB1570.namprd11.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <955B384899F25E4DB71431D5795E3B0E@namprd11.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: primarydata.com X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Dec 2016 22:40:56.1679 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 03193ed6-8726-4bb3-a832-18ab0d28adb7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB1569 X-MC-Unique: dF0TxhKAMpK12ioLQL-Vpg-1 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id uBFMfA5p032213 Content-Length: 7191 Lines: 221 > On Dec 9, 2016, at 08:41, Benjamin Coddington wrote: > > NFS has some optimizations for readdir to choose between using READDIR or > READDIRPLUS based on workload, and which NFS operation to use is determined > by subsequent interactions with lookup, d_revalidate, and getattr. > > Concurrent use of nfs_readdir() via ->iterate_shared() can cause those > optimizations to repeatedly invalidate the pagecache used to store > directory entries during readdir(), which causes some very bad performance > for directories with many entries (more than about 10000). > > There's a couple ways to fix this in NFS, but no fix would be as simple as > going back to ->iterate() to serialize nfs_readdir(), and neither fix I > tested performed as well as going back to ->iterate(). > > The first required taking the directory's i_lock for each entry, with the > result of terrible contention. > > The second way adds another flag to the nfs_inode, and so keeps the > optimizations working for large directories. The difference from using > ->iterate() here is that much more memory is consumed for a given workload > without any performance gain. > > The workings of nfs_readdir() are such that concurrent users are serialized > within read_cache_page() waiting to retrieve pages of entries from the > server. By serializing this work in iterate_dir() instead, contention for > cache pages is reduced. Waiting processes can have an uncontended pass at > the entirety of the directory's pagecache once previous processes have > completed filling it. > > This reverts commit 9ac3d3e8460e ("nfs: switch to ->iterate_shared()") > > Signed-off-by: Benjamin Coddington > --- > fs/nfs/dir.c | 71 ++++++++++++++++++++++++------------------------------------ > 1 file changed, 28 insertions(+), 43 deletions(-) > > diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c > index 7483722162fa..1905f3af5449 100644 > --- a/fs/nfs/dir.c > +++ b/fs/nfs/dir.c > @@ -57,7 +57,7 @@ static void nfs_readdir_clear_array(struct page*); > const struct file_operations nfs_dir_operations = { > .llseek = nfs_llseek_dir, > .read = generic_read_dir, > - .iterate_shared = nfs_readdir, > + .iterate = nfs_readdir, > .open = nfs_opendir, > .release = nfs_closedir, > .fsync = nfs_fsync_dir, > @@ -145,7 +145,6 @@ struct nfs_cache_array_entry { > }; > > struct nfs_cache_array { > - atomic_t refcount; > int size; > int eof_index; > u64 last_cookie; > @@ -201,20 +200,11 @@ void nfs_readdir_clear_array(struct page *page) > int i; > > array = kmap_atomic(page); > - if (atomic_dec_and_test(&array->refcount)) > - for (i = 0; i < array->size; i++) > - kfree(array->array[i].string.name); > + for (i = 0; i < array->size; i++) > + kfree(array->array[i].string.name); > kunmap_atomic(array); > } > > -static bool grab_page(struct page *page) > -{ > - struct nfs_cache_array *array = kmap_atomic(page); > - bool res = atomic_inc_not_zero(&array->refcount); > - kunmap_atomic(array); > - return res; > -} > - > /* > * the caller is responsible for freeing qstr.name > * when called by nfs_readdir_add_to_array, the strings will be freed in > @@ -491,7 +481,6 @@ static > void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry) > { > struct qstr filename = QSTR_INIT(entry->name, entry->len); > - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq); > struct dentry *dentry; > struct dentry *alias; > struct inode *dir = d_inode(parent); > @@ -519,13 +508,7 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry) > filename.hash = full_name_hash(parent, filename.name, filename.len); > > dentry = d_lookup(parent, &filename); > -again: > - if (!dentry) { > - dentry = d_alloc_parallel(parent, &filename, &wq); > - if (IS_ERR(dentry)) > - return; > - } > - if (!d_in_lookup(dentry)) { > + if (dentry != NULL) { This all looks like it is reverting to using an obsolete VFS API. I’d prefer an ACK from Al as to whether or not this is allowed. Please note that the rest of the lookup code is still parallelised. > /* Is there a mountpoint here? If so, just exit */ > if (!nfs_fsid_equal(&NFS_SB(dentry->d_sb)->fsid, > &entry->fattr->fsid)) > @@ -541,8 +524,6 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry) > } else { > d_invalidate(dentry); > dput(dentry); > - dentry = NULL; > - goto again; > } > } > if (!entry->fh->size) { > @@ -550,16 +531,23 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry) > goto out; > } > > + dentry = d_alloc(parent, &filename); > + if (dentry == NULL) > + return; > + > inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr, entry->label); > + if (IS_ERR(inode)) > + goto out; > + > alias = d_splice_alias(inode, dentry); > - d_lookup_done(dentry); > - if (alias) { > - if (IS_ERR(alias)) > - goto out; > - dput(dentry); > - dentry = alias; > - } > - nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); > + if (IS_ERR(alias)) > + goto out; > + else if (alias) { > + nfs_set_verifier(alias, nfs_save_change_attribute(dir)); > + dput(alias); > + } else > + nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); > + > out: > dput(dentry); > } > @@ -680,7 +668,6 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page, > goto out_label_free; > } > memset(array, 0, sizeof(struct nfs_cache_array)); > - atomic_set(&array->refcount, 1); > array->eof_index = -1; > > status = nfs_readdir_alloc_pages(pages, array_size); > @@ -743,7 +730,8 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page* page) > static > void cache_page_release(nfs_readdir_descriptor_t *desc) > { > - nfs_readdir_clear_array(desc->page); > + if (!desc->page->mapping) > + nfs_readdir_clear_array(desc->page); > put_page(desc->page); > desc->page = NULL; > } > @@ -751,16 +739,8 @@ void cache_page_release(nfs_readdir_descriptor_t *desc) > static > struct page *get_cache_page(nfs_readdir_descriptor_t *desc) > { > - struct page *page; > - > - for (;;) { > - page = read_cache_page(desc->file->f_mapping, > + return read_cache_page(desc->file->f_mapping, > desc->page_index, (filler_t *)nfs_readdir_filler, desc); > - if (IS_ERR(page) || grab_page(page)) > - break; > - put_page(page); > - } > - return page; > } > > /* > @@ -966,11 +946,13 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx) > > static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence) > { > + struct inode *inode = file_inode(filp); > struct nfs_open_dir_context *dir_ctx = filp->private_data; > > dfprintk(FILE, "NFS: llseek dir(%pD2, %lld, %d)\n", > filp, offset, whence); > > + inode_lock(inode); > switch (whence) { > case 1: > offset += filp->f_pos; > @@ -978,13 +960,16 @@ static loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int whence) > if (offset >= 0) > break; > default: > - return -EINVAL; > + offset = -EINVAL; > + goto out; > } > if (offset != filp->f_pos) { > filp->f_pos = offset; > dir_ctx->dir_cookie = 0; > dir_ctx->duped = 0; > } > +out: > + inode_unlock(inode); > return offset; > } > > -- > 2.9.3 >