Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp154672pxf; Wed, 17 Mar 2021 01:40:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxavYBjNgAmuI0gtwrPYIMPCJkbGggaml9GcnPhaRkSjXv1y61INY5Z0R83usyyxwSRVf2 X-Received: by 2002:a17:906:684b:: with SMTP id a11mr33231842ejs.329.1615970415926; Wed, 17 Mar 2021 01:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615970415; cv=none; d=google.com; s=arc-20160816; b=wxru9s0OUonQbxvRQUxYroTIxHvGV76rHydFYEhQvPM9KrstAN4+yeNP6DfdZSFvbi undeT/4DdN4kd7Q6a69rUtUKgcsbve8ktuvI3sjCPQGrWJXcSV5z0G3buhhfXQwWU+lY ntLLuiBE6JLaPshJns3At37GQ6DekTE3v+GN6GwgGGeKBRghikNr+BzvlSAm3vLWhGcn /9/9XvYqrXui4JDNXuSmVYTkpFxu6jgbG5PHyx5P+TSZsqroUcF2Qb1Gn1bWjmSNYyDl fc1dR5kKtQ03sX4cQ1UIofJhGMGvSUkfjYHodD0iZQaY91ukZDyXfeLFZEJR+lYk6rmi Ef0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=2i0xfPlcj0R7orAOCHVfIWfI1iiOnTAxO0LsIr7b+yo=; b=KLIRf95H9NlIuFQYdH5oIi1vLPWGBuIG6q0DU6JUpClgUV1DnO3stiU+fzdGr7m6kF XE/3iDLRAN1MMjL8FOnl3ofBXbmdl3v0xKtcspOUztWNU5xXPf7SguB0WxfOycFkIUGD 7x4gybqR6Q9tOJuAie0BErE3FClDokIIZXIbVKtGUTaJyvaeMf+j/HfrEVvyqLoPedNN psqX5+/AqJewo5/WK/Zdryh5lhQgdMy7p43r8dFQBlBKaoD7sgmeqcCY6Qo7qwXS/3w7 cxTiRKd0A72VuXQd8fcMbD1cRidXQ31cBtBL9JMhmtPBV6P06z4X0hJ1iGbSzeVNpWFM sVLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gPyIMb4j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si15006182edo.16.2021.03.17.01.39.53; Wed, 17 Mar 2021 01:40:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gPyIMb4j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbhCQIiz (ORCPT + 99 others); Wed, 17 Mar 2021 04:38:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbhCQIiq (ORCPT ); Wed, 17 Mar 2021 04:38:46 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6301C06174A for ; Wed, 17 Mar 2021 01:38:34 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id z2so899779wrl.5 for ; Wed, 17 Mar 2021 01:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=2i0xfPlcj0R7orAOCHVfIWfI1iiOnTAxO0LsIr7b+yo=; b=gPyIMb4jZqIQk6gaiWJgguRRKa7sKRivhhMPnxSXkJz86PkoitTBPbhizjRm+Hkmv3 4jTxGsxeuqA1Ui9h2hSSfb5ZIPA++1VzZU2GonexbyYYq7sQ1ER44TCiLaUUAgZodqS0 YH4DgsLLctyORruGmLYKCWT1s0eigXlx8UdPZvJuMVwOBnNoyHJYmM6pZDmZfMI+epHQ He8dnDcFtgYjOpxiKE8YQyaMhFNB/AFJqaShZ8DRBKyDeByvRYvMmQHHb61DonnT6IQ2 P/IqXjF/zrZHDvoqqXXl+JvvserIRqTnrHdmXQ+Rp0iy2TR2zMZsdyQXrMbMaxU+em09 G+xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=2i0xfPlcj0R7orAOCHVfIWfI1iiOnTAxO0LsIr7b+yo=; b=QTEugpPfRyrn3oF3LmBQqd2mRGmawYrUEKyhDWRurV02qMDwp84V8yfo56Gmgm55qC oprpgNF8Rerhkw5sR4KVNBirWkJ/MsbQsQhiHCCnptAGpEr7a3TvdnoSqO2bcXPUTQGj LfO8vVNHcJ2phn8J18Ft+XoSZXNoogZ3EheilAT2paEBSfE5Sz/vpGVeiH/ytf66NFaQ 4Q1X5aV6te3q/uWb0eK7zCABzAokNU4CWVIB43vG0/MF9jQED6YV4LGF1uUnFjHgor4S VfhB4PT5C2s/M6VO1ZDUDUzIXwnC4IFdjrXu4HWnVLTFn0VIviqEnKjqRQ7lyreaxsPk ttog== X-Gm-Message-State: AOAM53212iPlLBR6yoS9e56qlY4wA3jwvxOaag3RLYr5NIl8WwrxvZG6 4bzkxLtPz6P16os5YsSJT88= X-Received: by 2002:adf:82af:: with SMTP id 44mr3015737wrc.279.1615970313254; Wed, 17 Mar 2021 01:38:33 -0700 (PDT) Received: from gmail.com (54033286.catv.pool.telekom.hu. [84.3.50.134]) by smtp.gmail.com with ESMTPSA id g202sm1743891wme.20.2021.03.17.01.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 01:38:32 -0700 (PDT) Sender: Ingo Molnar Date: Wed, 17 Mar 2021 09:38:30 +0100 From: Ingo Molnar To: Nicholas Piggin Cc: linux-kernel@vger.kernel.org, Andrew Morton , Linus Torvalds , linux-mm@kvack.org, Anton Blanchard Subject: Re: [PATCH v2] Increase page and bit waitqueue hash size Message-ID: <20210317083830.GC3881262@gmail.com> References: <20210317075427.587806-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210317075427.587806-1-npiggin@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Nicholas Piggin wrote: > The page waitqueue hash is a bit small (256 entries) on very big systems. A > 16 socket 1536 thread POWER9 system was found to encounter hash collisions > and excessive time in waitqueue locking at times. This was intermittent and > hard to reproduce easily with the setup we had (very little real IO > capacity). The theory is that sometimes (depending on allocation luck) > important pages would happen to collide a lot in the hash, slowing down page > locking, causing the problem to snowball. > > An small test case was made where threads would write and fsync different > pages, generating just a small amount of contention across many pages. > > Increasing page waitqueue hash size to 262144 entries increased throughput > by 182% while also reducing standard deviation 3x. perf before the increase: > > 36.23% [k] _raw_spin_lock_irqsave - - > | > |--34.60%--wake_up_page_bit > | 0 > | iomap_write_end.isra.38 > | iomap_write_actor > | iomap_apply > | iomap_file_buffered_write > | xfs_file_buffered_aio_write > | new_sync_write > > 17.93% [k] native_queued_spin_lock_slowpath - - > | > |--16.74%--_raw_spin_lock_irqsave > | | > | --16.44%--wake_up_page_bit > | iomap_write_end.isra.38 > | iomap_write_actor > | iomap_apply > | iomap_file_buffered_write > | xfs_file_buffered_aio_write > > This patch uses alloc_large_system_hash to allocate a bigger system hash > that scales somewhat with memory size. The bit/var wait-queue is also > changed to keep code matching, albiet with a smaller scale factor. > > A very small CONFIG_BASE_SMALL option is also added because these are two > of the biggest static objects in the image on very small systems. > > This hash could be made per-node, which may help reduce remote accesses > on well localised workloads, but that adds some complexity with indexing > and hotplug, so until we get a less artificial workload to test with, > keep it simple. > > Signed-off-by: Nicholas Piggin > --- > kernel/sched/wait_bit.c | 30 +++++++++++++++++++++++------- > mm/filemap.c | 24 +++++++++++++++++++++--- > 2 files changed, 44 insertions(+), 10 deletions(-) > > diff --git a/kernel/sched/wait_bit.c b/kernel/sched/wait_bit.c > index 02ce292b9bc0..dba73dec17c4 100644 > --- a/kernel/sched/wait_bit.c > +++ b/kernel/sched/wait_bit.c > @@ -2,19 +2,24 @@ > /* > * The implementation of the wait_bit*() and related waiting APIs: > */ > +#include > #include "sched.h" > > -#define WAIT_TABLE_BITS 8 > -#define WAIT_TABLE_SIZE (1 << WAIT_TABLE_BITS) Ugh, 256 entries is almost embarrassingly small indeed. I've put your patch into sched/core, unless Andrew is objecting. > - for (i = 0; i < WAIT_TABLE_SIZE; i++) > + if (!CONFIG_BASE_SMALL) { > + bit_wait_table = alloc_large_system_hash("bit waitqueue hash", > + sizeof(wait_queue_head_t), > + 0, > + 22, > + 0, > + &bit_wait_table_bits, > + NULL, > + 0, > + 0); > + } > + for (i = 0; i < BIT_WAIT_TABLE_SIZE; i++) > init_waitqueue_head(bit_wait_table + i); Meta suggestion: maybe the CONFIG_BASE_SMALL ugliness could be folded into alloc_large_system_hash() itself? > --- a/mm/filemap.c > +++ b/mm/filemap.c > static wait_queue_head_t *page_waitqueue(struct page *page) > { > - return &page_wait_table[hash_ptr(page, PAGE_WAIT_TABLE_BITS)]; > + return &page_wait_table[hash_ptr(page, page_wait_table_bits)]; > } I'm wondering whether you've tried to make this NUMA aware through page->node? Seems like another useful step when having a global hash ... Thanks, Ingo