Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3311010ybl; Sun, 12 Jan 2020 14:59:38 -0800 (PST) X-Google-Smtp-Source: APXvYqxkbDtwkt7cjk6y7CJDy46epRGNi1JGYKS/02vJjq2EtkvgBEz9DMgXg5xDk+hL8iiGvo/c X-Received: by 2002:a05:6830:154c:: with SMTP id l12mr11196115otp.275.1578869978418; Sun, 12 Jan 2020 14:59:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578869978; cv=none; d=google.com; s=arc-20160816; b=u4NplCtqD2PKcgVZymzMWyHz2mg+NEg2kNDBQkrUfvQ5DxjG6Rh10Mwy61mVaThczb Qd69mRnY5EEaGvw3LVNpPnvBiG9asZ43Y7xNskbOZSSi34rVnh9ZE2u8lTpToKkFEnPd 9pyM5xLwfcFaWZuiRGdhWAO2KL5hLSfn7sBOfj5zqS1pmoB+jpOLL3DuRG4I2crrKBb/ +JAQWILzkX/d1kysplgjOr21p0+VMYw1RjX30CgQXydVuvdY+09SJ2U5oOWgwAvFsiJX lCYJNGVMbHc7alk8wdXJWS46YroptTqMGKzv+vF8LCgACZUs3qm0/FRkIwuwSwO4uBbv 2XQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=YhEnPWc7hBMgzTi8jrnUahHh/j3JJLesjhzD86DLwCs=; b=ZD7ZZRfYWBowOxVJXmIVUQsPH4PBcvRu15NxFKmW6ot4c4z18Ghpwd/KjGW74ebFJj ZjmlKoDQmxk0nj33b8w0CrwXwdb4peHskc1YQr6nSHWi4JkizW8iHzunonPyOi21XvJF Qs7dHCVutV2Lw8CKFwviQHm7jfvgvbXLb4WpQBVA4ZrBmnA6sADxMcC8z/WveHZv/GYU 4RiKqaUTTTJl85Uf/bMMJ7BuNO8z9goOC808t5J+eIa8Mwvr/WPu0R0+U/hUMO03FX6P Hs3uykbazGrokALe3irNHzX/8saH3nv4lmSHhFpwC9Wp/g4WS2RChl/ECUNCc4rItfFk Q06Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=17mnMprW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21si5799928otp.56.2020.01.12.14.59.26; Sun, 12 Jan 2020 14:59:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=17mnMprW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387469AbgALW5e (ORCPT + 99 others); Sun, 12 Jan 2020 17:57:34 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:45424 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727323AbgALW5e (ORCPT ); Sun, 12 Jan 2020 17:57:34 -0500 Received: by mail-lf1-f65.google.com with SMTP id 203so5440876lfa.12 for ; Sun, 12 Jan 2020 14:57:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=YhEnPWc7hBMgzTi8jrnUahHh/j3JJLesjhzD86DLwCs=; b=17mnMprWe4+SB2cTaLQImgJbVUQMzsjRXuwdjTe6KETCHH94Zi6GGwUo5/WsHFRbJL /NAoOp0F4Dj8T562fMLT2GENv5UucZ+oCPCg5+TMX0LVwjxzaxeNMIfdloCgKwLQ6QYs +aw6FaoTAN1olVQlSVat6zHRBfOtwJH4EV0K9WdxN9TvaTkUxjahKqF3aEHkUp4DgWjE ISIP32ImjX7TZHNBYrb04W84s7tWZ6Sr56cznaStx43sgf33DhEwl8jkvJd2ZBZ8vHkN 2Kck6f7sk1Y0y5vqhxkc+AODNs15YZjkIJf6xKEGBk1k6iBEWZkEVuqS6cyWL9xrpjCD 7BWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YhEnPWc7hBMgzTi8jrnUahHh/j3JJLesjhzD86DLwCs=; b=Ty94NVjrvQaX15iN1ig+4rnIYZd0SLgke2hpia6bxVACZX61DtNsp6AFiUje3fsNBb ctjGHji05PKdOZkonqmi6/+VoCsSjNDPmoY5tnHfLlqVTDmHuBkc0KBuf5E2/+2P7rCr u7oD//dTzg3r4l12CXIMVuae0ZCXthlmDO9ZoYot9XBBSb0XHDEb0L838OvsdOfa6UST 96l82lWZeEPxr6n5jD9MponeBMMOJyCdL2MXfTjYU5YPp1Qqjpchak/nLCIJ/sLlJKrI 27e8f00nGZBkvnI0lQTO3llq4RljxXVjryfMKxCi1erxB8STRHKUPDtf0RoeEvB637h4 HoOA== X-Gm-Message-State: APjAAAVsn5rHTIXNslbmF/ZDZK63InAmzFjjOKU+ejYR/sz/5DHlaA4H Df+qA3uegWtdflmgobfl8GG9sg== X-Received: by 2002:a19:c3cc:: with SMTP id t195mr7915631lff.144.1578869852309; Sun, 12 Jan 2020 14:57:32 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id r6sm4849697ljk.37.2020.01.12.14.57.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2020 14:57:31 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id 5BF79100376; Mon, 13 Jan 2020 01:57:18 +0300 (+03) Date: Mon, 13 Jan 2020 01:57:18 +0300 From: "Kirill A. Shutemov" To: Wei Yang Cc: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, yang.shi@linux.alibaba.com, alexander.duyck@gmail.com, rientjes@google.com Subject: Re: [Patch v2] mm: thp: grab the lock before manipulation defer list Message-ID: <20200112225718.5vqzezfclacujyx3@box> References: <20200109143054.13203-1-richardw.yang@linux.intel.com> <20200111000352.efy6krudecpshezh@box> <20200112022858.GA17733@richard> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200112022858.GA17733@richard> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 12, 2020 at 10:28:58AM +0800, Wei Yang wrote: > On Sat, Jan 11, 2020 at 03:03:52AM +0300, Kirill A. Shutemov wrote: > >On Thu, Jan 09, 2020 at 10:30:54PM +0800, Wei Yang wrote: > >> As all the other places, we grab the lock before manipulate the defer list. > >> Current implementation may face a race condition. > >> > >> For example, the potential race would be: > >> > >> CPU1 CPU2 > >> mem_cgroup_move_account split_huge_page_to_list > >> !list_empty > >> lock > >> !list_empty > >> list_del > >> unlock > >> lock > >> # !list_empty might not hold anymore > >> list_del_init > >> unlock > > > >I don't think this particular race is possible. Both parties take page > >lock before messing with deferred queue, but anytway: > > I am afraid not. Page lock is per page, while defer queue is per pgdate or > memcg. > > It is possible two page in the same pgdate or memcg grab page lock > respectively and then access the same defer queue concurrently. Look closer on the list_empty() argument. It's list_head local to the page. Too different pages can be handled in parallel without any problem in this particular scenario. As long as we as we modify it under the lock. Said that, page lock here was somewhat accidential and I still belive we need to move the check under the lock anyway. -- Kirill A. Shutemov