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=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, 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 414EBC33CB1 for ; Tue, 14 Jan 2020 10:59:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC2B3207FF for ; Tue, 14 Jan 2020 10:59:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="JIpiz5Ez" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC2B3207FF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3FE798E0005; Tue, 14 Jan 2020 05:59:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AE2B8E0003; Tue, 14 Jan 2020 05:59:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A5798E0005; Tue, 14 Jan 2020 05:59:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 125498E0003 for ; Tue, 14 Jan 2020 05:59:21 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id AD4668248047 for ; Tue, 14 Jan 2020 10:59:20 +0000 (UTC) X-FDA: 76375943280.30.fifth75_518172f4d8a05 X-HE-Tag: fifth75_518172f4d8a05 X-Filterd-Recvd-Size: 5678 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jan 2020 10:59:19 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id a13so13789925ljm.10 for ; Tue, 14 Jan 2020 02:59:19 -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=EW8+gP2rKs+jXbNSD4aXu/n/AKA3IlQufSB8tHR0hpU=; b=JIpiz5EzHfc1rirgM3SfKKD7NZ7xCQYzlJ6+GdvrzJUYHz0G/NH7/ld3OhUQ1HKJos dit9ovo9dYZmngzGa0fLrVJtCCmge5pehCyJvukToG0Nuv+ggS+HyPkXxoj4gKNforWB 3vF25MkaWlPZp3UnVggalYxD8ki4V8KGg6l3zKEO7hi+CMZjcWQzClCziiB9qV4c0NQe Vd5Jpf4zpbttEt6DWbC/XPpzESGs1GPdwXq70JoBVzV+q7XSQkIyCvpKAHFwKsHoCVuP Nvz4qrWH2849lEWqK2y1WXBpyP5s8Rs1cgCWkK7IYT2NdUv0t9yYFPNKfdSFKUodOQC2 OwUA== 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=EW8+gP2rKs+jXbNSD4aXu/n/AKA3IlQufSB8tHR0hpU=; b=FWwU0+nkZcQa3HEvCzck5IbVA4sHGxKSgvizdIUzSpzgW9whW2LOTh115FH+sHgH5H j7XL9v3QKpTEaJhAg5/0lvppYWw7dO9Lxv/60W+dxlkYMrIgIXhrEoxWo9RREok1SMNN QIsOF7HoVXgXT3qB9r2kYUYSWzd1O/0UtJmpg2ebM64uyGbeH/i8iNrE7cSucI49c90D BOlHLkSSoLRJur/UDg4HJBS/WBRO9H1ojEkR118P4z3qgLe4HVosG0JJFWGkphCkPTCZ 9qwMqoeAVEYyzAf5wB/WoEDpn8rwqYmIr0HKT9+Y4lAsp0rgn73gCbnqHbrhIR+IyZ5t 0Myw== X-Gm-Message-State: APjAAAXiWcYovbmn4+VKFAMDaKwuMsboedsc6gBdvQE0/aOrO5CRF+cx b3H60o6XjBkf180bQ5fB2NZ4DA== X-Google-Smtp-Source: APXvYqwwU+OYYmkkbYwhplcfbTT3Ys1dRt6HFgh5JXt2IjPqFpNbmHJc/3aC3GIv3Rs57FEF4FvMYA== X-Received: by 2002:a2e:8755:: with SMTP id q21mr13841462ljj.156.1578999558693; Tue, 14 Jan 2020 02:59:18 -0800 (PST) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id n23sm7139469lfa.41.2020.01.14.02.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 02:59:17 -0800 (PST) Received: by box.localdomain (Postfix, from userid 1000) id C2A23100823; Tue, 14 Jan 2020 13:59:21 +0300 (+03) Date: Tue, 14 Jan 2020 13:59:21 +0300 From: "Kirill A. Shutemov" To: Michal Hocko Cc: Wei Yang , hannes@cmpxchg.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: <20200114105921.eo2vdwikrvtt3gkb@box> References: <20200109143054.13203-1-richardw.yang@linux.intel.com> <20200111000352.efy6krudecpshezh@box> <20200114093122.GH19428@dhcp22.suse.cz> <20200114103112.o6ozdbkfnzdsc2ke@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200114103112.o6ozdbkfnzdsc2ke@box> User-Agent: NeoMutt/20180716 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 Tue, Jan 14, 2020 at 01:31:12PM +0300, Kirill A. Shutemov wrote: > On Tue, Jan 14, 2020 at 10:31:22AM +0100, Michal Hocko wrote: > > On Sat 11-01-20 03:03:52, 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: > > > > > > Acked-by: Kirill A. Shutemov > > > > I am confused, if the above race is not possible then what would be a > > real race? We really do not want to have a patch with a misleading > > changelog, do we? > > The alternative is to make sure that all page_deferred_list() called with > page lock taken. > > I'll look into it. split_huge_page_to_list() has page lock taken. free_transhuge_page() is in the free path and doesn't susceptible to the race. deferred_split_scan() is trickier. list_move() should be safe against list_empty() as it will not produce false-positive list_empty(). list_del_init() *should* (correct me if I'm wrong) be safe because the page is freeing and memcg will not touch the page anymore. deferred_split_huge_page() is a problematic one. It called from page_remove_rmap() path witch does require page lock. I don't see any obvious way to exclude race with mem_cgroup_move_account() here. Anybody else? Wei, could you rewrite the commit message with deferred_split_huge_page() as a race source instead of split_huge_page_to_list()? -- Kirill A. Shutemov