Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp308108ybi; Thu, 1 Aug 2019 19:32:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaOVApFdhh7KlSbBB0rca8YYpbyMqKMWJEIah7KS+MfI28fzH65TMvlE74ETf8gD3/jOEc X-Received: by 2002:a17:90a:28e4:: with SMTP id f91mr1852820pjd.99.1564713142668; Thu, 01 Aug 2019 19:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564713142; cv=none; d=google.com; s=arc-20160816; b=Hzhy9YPYeYj9KC9vbyRH2WghS4LOOktwnXoUaDOlFjvJriSkgRE2MNY54cZmCrCHY5 /Gxty6LUbjvj0R/WztPo+NdPwnz3MEbV6kxANFSbVFbXzVxFq9i4s+6sjnPGy4aNmzxu /sSR3ufTQAEnxD8ja8L7ePpnNhTlQew7jqWtkgkeerv+0m5nn1wE+3fnFVwuqW8+NvBX KVd26CoaBiG3S6E2q+Y91nK8yATumlIRKDvp84qyHnPe4hoP2sXAkQ2qVigoP6Ch8s+X 9mr/NBhR+RZfM06axTNEJl48gs9RZQyF7cexlbEVcYxGUBJiILIIRx56YFbNAZ1y+KAV A62g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=VKzEuSkmyrWV8LhwIH3JFAo5TpB9gh8PzM9j2uJXmIA=; b=uG7OG7gxtidSu6M91KWswdsogcYwPbChQkJEekSobY3IUMsaaEW9thLix+I+kHgzTD Au9pez4oAZkRiI1+QPJB0S+dfhEqSw6DmEmwCjKRnfqtI0T7RS9qXKNzD6ooo5eNdSW3 3GgqBcKYMa/7x6bv1xnLOYY4sk8Yt+ls3xp4lp/avjrFN3mfrsivGoJt5VNBCiZZI5uZ kv4N9n1fd77JfAgqsKO0k2jE/Q1FwOHu8CqT9X0sGf+uaN+SVsQtzGUUtYCzrrS4yhpy ydNoO9a+LPlvtERApZNA512ji1dSz/nFeXpmugQGdIyG/uR1kLujBeIZw2yMhEdAHH8h p4Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ljI7lFF3; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si5385709pjp.71.2019.08.01.19.32.07; Thu, 01 Aug 2019 19:32:22 -0700 (PDT) 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=@google.com header.s=20161025 header.b=ljI7lFF3; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727496AbfHBBxh (ORCPT + 99 others); Thu, 1 Aug 2019 21:53:37 -0400 Received: from mail-pf1-f202.google.com ([209.85.210.202]:45292 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfHBBxh (ORCPT ); Thu, 1 Aug 2019 21:53:37 -0400 Received: by mail-pf1-f202.google.com with SMTP id i27so47085702pfk.12 for ; Thu, 01 Aug 2019 18:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=VKzEuSkmyrWV8LhwIH3JFAo5TpB9gh8PzM9j2uJXmIA=; b=ljI7lFF3O1uGnDJgLjRw0nWAvDTSYyuHT002SegNqoGSSb9OLyCXLW4bvQwWX+qe6V V8wJyCYEPbFnkif6rt8y681avtdd4OXMPubBiEaIx1Lnxy6Lk4ro3uR/f0txJInnuZ0M yX2RYvNbUC3w9m+LKYUPbcjYgI+2S4RRgGV7dSs1rDRHmfuvkjs3QRY5Nom+99Lvujqy RVIFe5Kp3hVYnZpoOnuzgjOxx+c/yhMqr7N4KhLSFDHkeelY9Dec413o9Wt3oqVtk2ZU c8kH6QeWOT6aag7/h4j+Lzfi5RMbgcZlAgILtJrvzfZm0aWW409BAvH+WhXeRAiyeeoi zuTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=VKzEuSkmyrWV8LhwIH3JFAo5TpB9gh8PzM9j2uJXmIA=; b=Cn2/zawB5Um4/3ZJys2K5qSaSeKmKIC4tM5R4rI5a8vtCF1o0x7ARpxVqzoydauGHD HXPT0mrv8B185UIABGa+m5YiDbRc/3zl21TiPnShBw5oHDTwcZLgnYm3F2xcUpSTl3zx SqUv+iRUfZb3B1wmrvvLr/jlRz4T+nBkbpHxMdX3myVwJj3xDfi+erUlxINBMLv+wqiC nQ1q2iK8QI5rp8Tqrtp13yAyX80wGhUVsToNcbERHrFUoGWFXmN/quLeJ6HXYBxDx9UR YKCPUC6Qs59U9aabaqjANIT2oWRLiZp+kuJkaCOT6s/PKVLpyDV47m8awWKq/1B1f1ME +dkg== X-Gm-Message-State: APjAAAXjsfePO/AQg63jqhX9AzgRjBSvjwb/E+ee8YSoAozP56l4q6LZ PPktRUR7ZWaLMb2vqZhQW8X23WXwWrT97teg X-Received: by 2002:a63:f807:: with SMTP id n7mr125813928pgh.119.1564710816388; Thu, 01 Aug 2019 18:53:36 -0700 (PDT) Date: Thu, 1 Aug 2019 18:53:31 -0700 Message-Id: <20190802015332.229322-1-henryburns@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog Subject: [PATCH 1/2] mm/zsmalloc.c: Migration can leave pages in ZS_EMPTY indefinitely From: Henry Burns To: Minchan Kim , Nitin Gupta Cc: Sergey Senozhatsky , Shakeel Butt , Jonathan Adams , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Henry Burns Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In zs_page_migrate() we call putback_zspage() after we have finished migrating all pages in this zspage. However, the return value is ignored. If a zs_free() races in between zs_page_isolate() and zs_page_migrate(), freeing the last object in the zspage, putback_zspage() will leave the page in ZS_EMPTY for potentially an unbounded amount of time. To fix this, we need to do the same thing as zs_page_putback() does: schedule free_work to occur. To avoid duplicated code, move the sequence to a new putback_zspage_deferred() function which both zs_page_migrate() and zs_page_putback() call. Signed-off-by: Henry Burns --- mm/zsmalloc.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 1cda3fe0c2d9..efa660a87787 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1901,6 +1901,22 @@ static void dec_zspage_isolation(struct zspage *zspage) zspage->isolated--; } +static void putback_zspage_deferred(struct zs_pool *pool, + struct size_class *class, + struct zspage *zspage) +{ + enum fullness_group fg; + + fg = putback_zspage(class, zspage); + /* + * Due to page_lock, we cannot free zspage immediately + * so let's defer. + */ + if (fg == ZS_EMPTY) + schedule_work(&pool->free_work); + +} + static void replace_sub_page(struct size_class *class, struct zspage *zspage, struct page *newpage, struct page *oldpage) { @@ -2070,7 +2086,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage, * the list if @page is final isolated subpage in the zspage. */ if (!is_zspage_isolated(zspage)) - putback_zspage(class, zspage); + putback_zspage_deferred(pool, class, zspage); reset_page(page); put_page(page); @@ -2115,15 +2131,9 @@ static void zs_page_putback(struct page *page) spin_lock(&class->lock); dec_zspage_isolation(zspage); - if (!is_zspage_isolated(zspage)) { - fg = putback_zspage(class, zspage); - /* - * Due to page_lock, we cannot free zspage immediately - * so let's defer. - */ - if (fg == ZS_EMPTY) - schedule_work(&pool->free_work); - } + if (!is_zspage_isolated(zspage)) + putback_zspage_deferred(pool, class, zspage); + spin_unlock(&class->lock); } -- 2.22.0.770.g0f2c4a37fd-goog