From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81819C433E3 for ; Fri, 24 Jul 2020 15:24:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3F16920714 for ; Fri, 24 Jul 2020 15:24:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FIixSJFw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F16920714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A93F38D0021; Fri, 24 Jul 2020 11:24:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A44938D0020; Fri, 24 Jul 2020 11:24:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 959D28D0021; Fri, 24 Jul 2020 11:24:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 7EB468D0020 for ; Fri, 24 Jul 2020 11:24:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1805D8248047 for ; Fri, 24 Jul 2020 15:24:33 +0000 (UTC) X-FDA: 77073341226.26.pie80_0a1318a26f48 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id D773D18029B39 for ; Fri, 24 Jul 2020 15:24:32 +0000 (UTC) X-HE-Tag: pie80_0a1318a26f48 X-Filterd-Recvd-Size: 5410 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 15:24:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595604271; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5S4LFFufUCLzyfla7YE3yrAMSl5PTYaLTnMam8y5Ck0=; b=FIixSJFwlfeLKy4NXoJhB75WJsR+DX1gm7GmgQmktczl5SuodjtdRhULd+Dw/G2PMpO54D 1y41cp9dWuLNG+x/U8dOgTJRMH0widcyi+XYX2iY0hia+1Y6/QMjuDy6vh86Pn0sIQm0/E JYgp5lbmBUe1ljqwC3xke5Nq6IkGywU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-499-NSHLOZ7cNXi5LB6e4jUxbQ-1; Fri, 24 Jul 2020 11:24:29 -0400 X-MC-Unique: NSHLOZ7cNXi5LB6e4jUxbQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4BE2919057A1; Fri, 24 Jul 2020 15:24:28 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.121]) by smtp.corp.redhat.com (Postfix) with SMTP id 3F0242DE7F; Fri, 24 Jul 2020 15:24:26 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 24 Jul 2020 17:24:27 +0200 (CEST) Date: Fri, 24 Jul 2020 17:24:25 +0200 From: Oleg Nesterov To: Linus Torvalds Cc: Hugh Dickins , Michal Hocko , Linux-MM , LKML , Andrew Morton , Tim Chen , Michal Hocko Subject: Re: [RFC PATCH] mm: silence soft lockups from unlock_page Message-ID: <20200724152424.GC17209@redhat.com> References: <20200723124749.GA7428@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Rspamd-Queue-Id: D773D18029B39 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 07/23, Linus Torvalds wrote: > > But I'll walk over my patch mentally one more time. Here's the current > version, anyway. Both patches look correct to me, feel free to add Reviewed-by: Oleg Nesterov > @@ -1013,18 +1014,40 @@ static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, > if (wait_page->bit_nr != key->bit_nr) > return 0; > > + /* Stop walking if it's locked */ > + if (wait->flags & WQ_FLAG_EXCLUSIVE) { > + if (test_and_set_bit(key->bit_nr, &key->page->flags)) > + return -1; > + } else { > + if (test_bit(key->bit_nr, &key->page->flags)) > + return -1; > + } not sure this makes any sense, but this looks like another user of trylock_page_bit_common(), see the patch below on top of 1/2. Oleg. --- mm/filemap.c~ 2020-07-24 17:09:34.728133846 +0200 +++ mm/filemap.c 2020-07-24 17:23:52.279185374 +0200 @@ -1000,6 +1000,14 @@ wait_queue_entry_t wait; }; +static int trylock_page_bit_common(struct page *page, int bit_nr, + struct wait_queue_entry *wait) +{ + return wait->flags & WQ_FLAG_EXCLUSIVE ? + !test_and_set_bit(bit_nr, &page->flags) : + !test_bit(bit_nr, &page->flags); +} + static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *arg) { int ret; @@ -1015,13 +1023,8 @@ return 0; /* Stop walking if it's locked */ - if (wait->flags & WQ_FLAG_EXCLUSIVE) { - if (test_and_set_bit(key->bit_nr, &key->page->flags)) - return -1; - } else { - if (test_bit(key->bit_nr, &key->page->flags)) - return -1; - } + if (!trylock_page_bit_common(key->page, key->bit_nr, wait)) + return -1; /* * Let the waiter know we have done the page flag @@ -1126,14 +1129,6 @@ */ }; -static inline int trylock_page_bit_common(struct page *page, int bit_nr, - enum behavior behavior) -{ - return behavior == EXCLUSIVE ? - !test_and_set_bit(bit_nr, &page->flags) : - !test_bit(bit_nr, &page->flags); -} - static inline int wait_on_page_bit_common(wait_queue_head_t *q, struct page *page, int bit_nr, int state, enum behavior behavior) { @@ -1170,7 +1165,7 @@ */ spin_lock_irq(&q->lock); SetPageWaiters(page); - if (!trylock_page_bit_common(page, bit_nr, behavior)) + if (!trylock_page_bit_common(page, bit_nr, wait)) __add_wait_queue_entry_tail(q, wait); spin_unlock_irq(&q->lock);