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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 648BFC433EF for ; Thu, 3 Mar 2022 22:45:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB2708D0002; Thu, 3 Mar 2022 17:45:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E612A8D0001; Thu, 3 Mar 2022 17:45:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4F978D0002; Thu, 3 Mar 2022 17:45:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id C66A38D0001 for ; Thu, 3 Mar 2022 17:45:30 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 87E489F5F2 for ; Thu, 3 Mar 2022 22:45:30 +0000 (UTC) X-FDA: 79204558020.29.46055CA Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by imf22.hostedemail.com (Postfix) with ESMTP id 0D3EFC0006 for ; Thu, 3 Mar 2022 22:45:29 +0000 (UTC) Received: by mail-qv1-f43.google.com with SMTP id b12so5334453qvk.1 for ; Thu, 03 Mar 2022 14:45:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=ysKBNxNLKT+vRt9gn94ucU0jwaoAouI3FbJF/PEULzk=; b=sXWeRbLq4UaAh17wkVQx8uuykP8lWSZeZ1dyvi17P0USyM6x0HZAmMz8ssRLIzxQhj lvBnrlYFdI+KxhGdhWGFs1Iuu6cNSk7AvmhmNUwtZlZNHZsJToaEPTbSNgK9sNJN9NGl onWemrqQRXW6omvo90HpnQPtZ6IlAocKzXMW3WXamWfkwp0nHBxZquhoSgUQMFCzDKfM ZmFuYUDzGc95uNvzaVTetrPBNEz+9enSuoL77/kVedq6mgQOwIcWChvB1/ysYB7KTJ/k JeeSTLt1O/o7MMJs3aPg+nd04/yxMBzqiXBLz0V4AQQ6ruzcunjPM+6WNOME3HUf4/4d KUaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=ysKBNxNLKT+vRt9gn94ucU0jwaoAouI3FbJF/PEULzk=; b=wpqpFZ0kk4mSMkONaEM50xpZlx7PR8VTdAopuHPamhMw00d+vr/G/uZwO7wFKa79I/ 8L9MUq7/UCpy/7Vl19lLBXwuIeM/hYFtKVsZVh75foYOF5GH+U0WqDgQBEiEtYGxepv3 2xaEO8e8Ab5mlZWSZbVp1gLQo1eKhKkZ5goSqy4arPfMfIXU3Ed+dKQ7nAk9cuC/VnlC mHRUa1IKbP7IRot5q1q7brDbSbtOsMDvldoSS0N+sQTdoI3aCgt04yP3/Rmfja2LuJvI HvnIvi03xuwoBVMsppDwny6g3brdfUQw58wKDPyauQ1bMvnYjwZ2FL0XFsBc2bMr5BlJ MOLA== X-Gm-Message-State: AOAM531Y2YAJ0rN+I3mtb/gThclm41/Ur7rTg1WAODEuaaeBRRHq0El+ HpsY3013NyKq1rrjceHs+6++8w== X-Google-Smtp-Source: ABdhPJxhJMD24ooliUoMuYhm3iPyw4jcHyKNSLQ57nc6x0R4tlGMAULfCW/XD3OnCeNRhMurk1Wldg== X-Received: by 2002:ad4:5bc1:0:b0:42c:37be:6ac3 with SMTP id t1-20020ad45bc1000000b0042c37be6ac3mr26114521qvt.18.1646347529079; Thu, 03 Mar 2022 14:45:29 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id o18-20020a05622a139200b002de25b59013sm2418690qtk.84.2022.03.03.14.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Mar 2022 14:45:28 -0800 (PST) Date: Thu, 3 Mar 2022 14:45:26 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Yang Shi cc: Hugh Dickins , Andrew Morton , Ralph Campbell , Zi Yan , "Kirill A. Shutemov" , Linux Kernel Mailing List , Linux MM Subject: Re: [PATCH mmotm] mm/thp: refix __split_huge_pmd_locked() for migration PMD In-Reply-To: Message-ID: <72bcebad-b1e3-efd-ab72-9a86c76f70c1@google.com> References: <84792468-f512-e48f-378c-e34c3641e97@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 0D3EFC0006 X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sXWeRbLq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of hughd@google.com designates 209.85.219.43 as permitted sender) smtp.mailfrom=hughd@google.com X-Stat-Signature: hetgg4hemakm5bgmxodzajr6ermtex8x X-HE-Tag: 1646347529-307057 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 Thu, 3 Mar 2022, Yang Shi wrote: > On Wed, Mar 2, 2022 at 5:43 PM Hugh Dickins wrote: > > > > Migration entries do not contribute to a page's reference count: move > > __split_huge_pmd_locked()'s page_ref_add() into pmd_migration's else > > block (along with the page_count() check - a page is quite likely to > > to have reference count frozen to 0 when a migration entry is found). > > > > This will fix a very rare anonymous memory leak, after a split_huge_pmd() > > raced with an anon split_huge_page() or an anon THP migrate_pages(): since > > the wrongly raised refcount stopped the page (perhaps small, perhaps huge, > > depending on when the race hit) from ever being freed. At first I thought > > there were worse risks, from prematurely unfreezing a frozen page: but now > > think that would only affect page cache pages, which do not come this way > > (except for anonymous pages in swap cache, perhaps). > > Thanks for catching this. I agree there may be anon memory leak due to > bumped refcount. But I don't think it could affect page cache page > since that code (bumping refcount) is never called for page cache page > IIUC. Yes, that's what I meant by unfreezing "would only affect page cache pages, which do not come this way". But then remembered that anonymous pages in swap cache also have non-NULL page_mapping(), and involve freezing in the same way that page cache pages do. Now, offhand I forget the status of hugepage swap, so maybe that's impossible, hence "perhaps". Easier to fix than to think through all the ramifications of not fixing, as usual. > > The patch looks good to me. Reviewed-by: Yang Shi Thanks, Hugh