Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp818628ybh; Tue, 21 Jul 2020 08:36:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoBaI75Z+LCMzyghLmRx+V4J6mbDylwn7R5eBDjXAr2LbTPPYgVvX18gNNaVT86opedAlb X-Received: by 2002:a17:906:31c8:: with SMTP id f8mr24854973ejf.269.1595345792487; Tue, 21 Jul 2020 08:36:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595345792; cv=none; d=google.com; s=arc-20160816; b=G1MFpUl/ztdFDSYSGZFtHDmyegI2vb12R7BvKQ0+LHRzVk9eRxCzPO4J5/xBWBI889 6jcDTAoCMr83Xcmxm+xR+IkhJ8/C3FWC5ciyCM0k3OFrxCwPOV9s3ly1zBb6/ofUkjil qIVj52OeMFxELgd7FfgNUaPtdDcFIiqmqmSEN45u9OuV3mTHbP2d+EXVsaXBJUmbg/6+ uwP830ApycteKztNSd5g7+1SkLQhqw9hhOpYKHMuDOnWT23JOMBu+yngQoqsLXH2jE8X JotVCAO9YvuJCUkOCMMn6oqN52gxRGvZuu7MCsx+IIy9SraDheBQSSS3JS7urM+rDxO7 95qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=njynPEuSAx3YutPUm1Ks7mASPVE5qpU/6FLY7l0S5aI=; b=I7mJ81fmKSxT9GVAURlzWXkkWBaXGXveomRXBOmyvFpT+a/XcX/zirNx5Zzk9/+8F1 YXl3BKByuh9xX1NsabxAYcPKlS/LFTO1XCN7fy9HE4F/WT2jBrG355i34vXImZuRviNm ZmGYvDL8/rGpCt04mFcQZZPR8KM4hY3Qp+H4ODlQPkjn7vmUilc228rTAwUq0BDel8Wp DxcODafdODhxQBGy6MciLGi4mXL521tVFv48V8AlyJizCM6lfYCIVUoXoxuBWwx4+s7I pssUkzAcr/+Q7ZsJVp6U8zt1SLWeouaPzJorEZVHELOHIts9cUtvs7Dm8KlDkE8yhhOJ sOTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=eQ7WI6xk; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs7si12328727ejb.262.2020.07.21.08.36.06; Tue, 21 Jul 2020 08:36:32 -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=@linux-foundation.org header.s=google header.b=eQ7WI6xk; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728342AbgGUPdx (ORCPT + 99 others); Tue, 21 Jul 2020 11:33:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726919AbgGUPdx (ORCPT ); Tue, 21 Jul 2020 11:33:53 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07433C061794 for ; Tue, 21 Jul 2020 08:33:53 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id k13so2939264lfo.0 for ; Tue, 21 Jul 2020 08:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=njynPEuSAx3YutPUm1Ks7mASPVE5qpU/6FLY7l0S5aI=; b=eQ7WI6xkilW9FmgBXW/xysDF/3IDtBx6ypESMtBihC1eSPJLn5eC8eHS5o6dVcno9s vwH7lLb02YEl6fLuBANrEc7wsinozUQG/BuWIv3nBwdXFniYX41S1JKBigNvoypkkWDt v7e3VdKkBjijF9BamxUZuXGlgb38adI4J9jRE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=njynPEuSAx3YutPUm1Ks7mASPVE5qpU/6FLY7l0S5aI=; b=k9CfoI7Nak32nFGNz8gYBmPPB7TohseDbNyRLFIOPAV6cRq2ffh2YgOUOH2mLeON0o 3Oi9wsKdZnrHoF8ujypl3vA30YAYtwR4aH5P1NXKjtB/2ZOFs2c9efXUiVDaZy50fsKp fJjSudsyWjcNaMmxS6C4/+YJPW5kOH+7sDALTV3XhTVy6nLPeuGTGEsikYinUwh02WMJ spAz6tEOZvpwUBF5Q0pOQM9ANWE0SDRGstd4Yz3FH0KJE78HtqYhzo2qQT8Qqp41mGCV XviE7LVkPbWTcNmqNZ2GDzVl71EDFUMLDUmhh37OSie4aY9776vbmyPxQqmR0bSHkuXQ DCbg== X-Gm-Message-State: AOAM532YwyHpe5E0bIjT7h5O0U5a1Mx7yEib2rYjfkC5npV7R/ajerO1 UCy2KFUYJmE1jxuu9o4xUfVlSmulyZs= X-Received: by 2002:ac2:4241:: with SMTP id m1mr13966554lfl.20.1595345630949; Tue, 21 Jul 2020 08:33:50 -0700 (PDT) Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com. [209.85.167.41]) by smtp.gmail.com with ESMTPSA id b16sm4600173ljp.124.2020.07.21.08.33.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jul 2020 08:33:50 -0700 (PDT) Received: by mail-lf1-f41.google.com with SMTP id 140so1520652lfi.5 for ; Tue, 21 Jul 2020 08:33:49 -0700 (PDT) X-Received: by 2002:ac2:58d5:: with SMTP id u21mr3650183lfo.31.1595345629595; Tue, 21 Jul 2020 08:33:49 -0700 (PDT) MIME-Version: 1.0 References: <20200721063258.17140-1-mhocko@kernel.org> In-Reply-To: <20200721063258.17140-1-mhocko@kernel.org> From: Linus Torvalds Date: Tue, 21 Jul 2020 08:33:33 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH] mm: silence soft lockups from unlock_page To: Michal Hocko Cc: Linux-MM , LKML , Andrew Morton , Tim Chen , Michal Hocko Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 20, 2020 at 11:33 PM Michal Hocko wrote: > > The lockup is in page_unlock in do_read_fault and I suspect that this is > yet another effect of a very long waitqueue chain which has been > addresses by 11a19c7b099f ("sched/wait: Introduce wakeup boomark in > wake_up_page_bit") previously. Hmm. I do not believe that you can actually get to the point where you have a million waiters and it takes 20+ seconds to wake everybody up. More likely, it's actually *caused* by that commit 11a19c7b099f, and what might be happening is that other CPU's are just adding new waiters to the list *while* we're waking things up, because somebody else already got the page lock again. Humor me.. Does something like this work instead? It's whitespace-damaged because of just a cut-and-paste, but it's entirely untested, and I haven't really thought about any memory ordering issues, but I think it's ok. The logic is that anybody who called wake_up_page_bit() _must_ have cleared that bit before that. So if we ever see it set again (and memory ordering doesn't matter), then clearly somebody else got access to the page bit (whichever it was), and we should not (a) waste time waking up people who can't get the bit anyway (b) be in a livelock where other CPU's continually add themselves to the wait queue because somebody else got the bit. and it's that (b) case that I think happens for you. NOTE! Totally UNTESTED patch follows. I think it's good, but maybe somebody sees some problem with this approach? I realize that people can wait for other bits than the unlocked, and if you're waiting for writeback to complete maybe you don't care if somebody else then started writeback *AGAIN* on the page and you'd actually want to be woken up regardless, but honestly, I don't think it really matters. Linus --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1054,6 +1054,15 @@ static void wake_up_page_bit(struct page *page, int bit_nr) * from wait queue */ spin_unlock_irqrestore(&q->lock, flags); + + /* + * If somebody else set the bit again, stop waking + * people up. It's now the responsibility of that + * other page bit owner to do so. + */ + if (test_bit(bit_nr, &page->flags)) + return; + cpu_relax(); spin_lock_irqsave(&q->lock, flags); __wake_up_locked_key_bookmark(q, TASK_NORMAL, &key, &bookmark);