Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1311687pxf; Fri, 9 Apr 2021 05:33:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxojvzeMWDvR31mLz1SXsefBHb7Q3UxY1xkrmIbEDTTdvnDsM5fGzVhKSrQAmtS1EauK+uE X-Received: by 2002:a17:90a:fe90:: with SMTP id co16mr14172181pjb.231.1617971631331; Fri, 09 Apr 2021 05:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617971631; cv=none; d=google.com; s=arc-20160816; b=Rp6HLypH89Z8MVgRGRp+e42AQyZI1Fm36yQxNSc+6uYI/PDM10Z5F//MiAEvTubOse 7AvoioVAy46H/4xZi5bcb+3EnsF10rkCXhwsKn9IqyhyJqsuoMwcaTfMtgp+UTFDX/NK ySWcS6PKVDliCc5+LhkausiYIVQ1Ua6bDv6jNZEE7noxslKEOYawpr9uKHvU/X+f2nwB h5jRFtW2xW9JuJgRXy8jRAfHzctbqyNGUkxrWBF0mwknfr5mJV7v09NdVhYlOKB/uIuJ csOg9H9aouPt84h4/QoB8MrSyksbj+bA3wFfTDMYp51MfRhTbEt8g0aokXN27bwUUK9+ MLLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zEHZ5qG2Y9NIbhhZ3B17EZ5gBaH7ne5FjVmUdr7WNhw=; b=I0e1Qo8LKQvD03DhzI0DZLvR+3JvInjjf2DbCL8xUBZee0zgyROz6dpX8h1T7V25wi 4sjzoC3ZJ+HFAjifxp/Rojl9X5KCFc4LFmmioXlgqDfm7rPACV/VS4+ldBfH42Jj+Acj xXAsYaj04MC/FMKo/4Y4Le60Fh//y8e7AUUW4TaA94zI4whATufleGO0DVoDLDYielw1 yZoVcJ6Wttjb1tXH1BiNUFbMNJRkhoJCXeB2LvD4EUSZe9cAAA3kH7zt66aev6e9Zlxa SX3RBuLcvR0ghve1oM5TRf5jkAh8AgK9fV5LRah3kOTZ98CfOzKEGq4gOjpJhYD48f7b 7AwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=HhI9y7yk; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fv11si2916693pjb.30.2021.04.09.05.33.37; Fri, 09 Apr 2021 05:33:51 -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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=HhI9y7yk; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbhDIMc4 (ORCPT + 99 others); Fri, 9 Apr 2021 08:32:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233673AbhDIMcq (ORCPT ); Fri, 9 Apr 2021 08:32:46 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F37C061760 for ; Fri, 9 Apr 2021 05:32:34 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id kk2-20020a17090b4a02b02900c777aa746fso3114520pjb.3 for ; Fri, 09 Apr 2021 05:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zEHZ5qG2Y9NIbhhZ3B17EZ5gBaH7ne5FjVmUdr7WNhw=; b=HhI9y7ykMy8qmjJd8T6jqQ4HxvvjCcyyeW1xVnQfYtZzlES1KSGQ85Q+DfM9GA7CQi SSIlTfC85Xfx/2gq/5GAnU3p9Foxs6ZApRZK2Ijcw2U8vzpqhy8cjpb9EaZgJEJf2Prs eX/U+LX5IkGaJlbTsgcf5zxP26U7l2ydVfxd865qVJYe7cdjeRVszFRwhdq/gNIwuJgm pCBHrk6ItplIEzUe8TbAm6EW+anIgZWthNuQ6hpKDJaf+0kyBN/LHB268iJFmdRMG1nE Dfi9W6U6lCMtkd5hUkMVeLoQUN1Tnl7ze1uAPrmGFcMe5HzgDSYaSCvoyA91sxWYLpid 3lwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zEHZ5qG2Y9NIbhhZ3B17EZ5gBaH7ne5FjVmUdr7WNhw=; b=Aajd62JYSoSRsEgLyi+JH+xSHXE5wCa0XOkBGaq2IYzBhbn59zT+ObL0UyV9Qrzodh FB/Vifo5zcJe4sbuOy4RBWKGPDDFBP+ciMSA/uyeV3QFUcLervi8sLrJYVjRtog3UfMM 9N80KrVNwLFCukvkgk0ms11xPAtq09Q3yjIsrUZOL3ZRKubpQEw2H7xAdLvWbv2qB5a8 DXTTMXay0Lr/aySH2xt0xe4xXRxELwkok+FzOZRwcq5d5mUiiujYep/k/RpH4EDi9BsY hk0Z3ZVJ6MxigqNi+N5Z3lvYYI+gGuUYAx1o5++XQ1W+g7foqEjetQ396f3g646is5y2 nS+g== X-Gm-Message-State: AOAM531MXIPR6hL/eo3pvv9FUwES9OBZQq9cMFjfhdI8B7ldClIt7EjH G4v52CprD0sEV4hd4K13lmf8Dg== X-Received: by 2002:a17:90a:156:: with SMTP id z22mr14391859pje.181.1617971553903; Fri, 09 Apr 2021 05:32:33 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id t3sm2167785pfg.176.2021.04.09.05.32.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Apr 2021 05:32:33 -0700 (PDT) From: Muchun Song To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, bsingharora@gmail.com, shy828301@gmail.com, alex.shi@linux.alibaba.com, Muchun Song Subject: [RFC PATCH v2 07/18] mm: memcontrol: introduce compact_lock_page_lruvec_irqsave Date: Fri, 9 Apr 2021 20:29:48 +0800 Message-Id: <20210409122959.82264-8-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210409122959.82264-1-songmuchun@bytedance.com> References: <20210409122959.82264-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we reuse the objcg APIs to charge LRU pages, the page_memcg() can be changed when the LRU pages reparented. In this case, we need to acquire the new lruvec lock. lruvec = mem_cgroup_page_lruvec(page); // The page is reparented. compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); // Acquired the wrong lruvec lock and need to retry. But compact_lock_irqsave() only take lruvec lock as the parameter, we cannot aware this change. If it can take the page as parameter to acquire the lruvec lock. When the page memcg is changed, we can use the page_memcg() detect whether we need to reacquire the new lruvec lock. So compact_lock_irqsave() is not suitable for us. Similar to lock_page_lruvec_irqsave(), introduce compact_lock_page_lruvec_irqsave() to acquire the lruvec lock in the compaction routine. Signed-off-by: Muchun Song --- mm/compaction.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index e7da342003dd..c9efe3542b0a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -511,6 +511,29 @@ static bool compact_lock_irqsave(spinlock_t *lock, unsigned long *flags, return true; } +static struct lruvec * +compact_lock_page_lruvec_irqsave(struct page *page, unsigned long *flags, + struct compact_control *cc) +{ + struct lruvec *lruvec; + + lruvec = mem_cgroup_page_lruvec(page); + + /* Track if the lock is contended in async mode */ + if (cc->mode == MIGRATE_ASYNC && !cc->contended) { + if (spin_trylock_irqsave(&lruvec->lru_lock, *flags)) + goto out; + + cc->contended = true; + } + + spin_lock_irqsave(&lruvec->lru_lock, *flags); +out: + lruvec_memcg_debug(lruvec, page); + + return lruvec; +} + /* * Compaction requires the taking of some coarse locks that are potentially * very heavily contended. The lock should be periodically unlocked to avoid @@ -1040,10 +1063,8 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (locked) unlock_page_lruvec_irqrestore(locked, flags); - compact_lock_irqsave(&lruvec->lru_lock, &flags, cc); - locked = lruvec; - - lruvec_memcg_debug(lruvec, page); + locked = compact_lock_page_lruvec_irqsave(page, &flags, cc); + lruvec = locked; /* Try get exclusive access under lock */ if (!skip_updated) { -- 2.11.0