From nobody Fri Jan 31 00:06:12 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 976B118EA2 for ; Mon, 27 Jan 2025 08:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737964993; cv=none; b=d5SclviVpo39BwyZT7SU0Yw5B1XdiMfkWeWtyum8bIQ2XBZczNZmfm9LMqc8hhgbBS5HUKU44Sf0k9Pd7CAv2XbXTzl+hQebiu4mqvKxf8bvDMByVC7+0797K4NGBBaR9Ol42A+jTfd8f2l8aTAJt9QCY6sZza2261golTvFbGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737964993; c=relaxed/simple; bh=QUjQOC+hjtTurq+rcuMEFoSwVg9zm/Zkjv0XpDY00c8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N+5pp7P693jkt3PZRot76VgbHjJ8bi+ZcjFLZ3sAIL81YUsFY7WbgJNLE4WySRd0PTHao77bCdibuCAbs5EgwQGOTgKhaniwDgFhq8rVkCh1/R6BoAlpHIio2rgewJJpZDkDDdTFfqrSWoWcUOiE4umpChKn6qZocJxV5c8/DiI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=oe3lhESb; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="oe3lhESb" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21a7ed0155cso65853575ad.3 for ; Mon, 27 Jan 2025 00:03:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1737964991; x=1738569791; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9BKLEcG6n3DfmSf8Cjanopzri1qniom6oLk870hy4qs=; b=oe3lhESb5T8Ehfkg0C/0KQWBuOLi7im59CqXz1kPuei2bpwC07EH7uvwa3o4jrhq8r bTCYjWoS4NMlI7SWpZ0NurQ72EPnfPm8ntfywDk39iD+O5Tkk+1+2xjhCegj1zS0BrJ0 cM/reYhzUdnyS+5oLsfvWqR1YFL3H8AGbURYE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737964991; x=1738569791; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9BKLEcG6n3DfmSf8Cjanopzri1qniom6oLk870hy4qs=; b=gQZnO6bQuVf40bRIhfdzt5lC/f4u74XfB4zqRK/mD4OCDbmjJYxpaNEJ0vkXjTNSeq vSX240V585pHiytVSC0b7uYbuSAumIHH0y3e6MDhPZj5QyiVT2NfSjeDxagRhnFx4j46 IeMUH22gQE2tymGz2Unz8OcFFtGkaILK3A8SfU2WH+bfnmXfXU3rHY9V9YcPQnmCu4Hz 6EVpG3S9tkc6GOewsNTdr8/eGx+BwwBa8ZxOsZNXULek0njs0SYBR7zdqIHCHRl3JxwX w5R62Al5kywFIlzmNFVx7VBwFYGey/mEXs2W13IWMc+UJdrtMeM/pRJsiW01AqzmwQUz NG/g== X-Forwarded-Encrypted: i=1; AJvYcCXnrKv9CSa0e/lcnJpMTVXqMDWQ4XdyiKL5lGH/FEDCcIWRzJugZzEfevabLQzItE6FkEKaM4n0U6yhzM0=@vger.kernel.org X-Gm-Message-State: AOJu0YwpULKE/kwTUZUCCukewS1z956amRICjmLFrEXf7ub1pSHY1pY6 G6VFGnsm815tDlrX8BQhyrVNxnxdzpCE23lQ3Pp4lezV/YG7hVfd3h4c6/CAuA== X-Gm-Gg: ASbGnct76xRu1yMrLk6l00dWXHVDGsDW81NqzqMIizd+7Oe8EVx3IVHdn2Ur8yvjQ/1 4RnIHVYyfcP7v1VMhfqWUbDyk5BPZkPN8gl2yKZI6zz82b44976X5Un0DwuvnXFwqqUmxlhmT2k 2PjRDTAAw7u4KA7I4cYb5PHVsIrLKOnVfYdVpiDcpDeHmfLd/2XD7m86zUhKJdHCSroyqJ6zTWx +AeNireSoF7js+MnBKy2n/vs5l9CUNV/v8UU5/YIx3R0BwcvcVDvm0rUHELARM6B1AfFcqpTG2T 7XC3J/o= X-Google-Smtp-Source: AGHT+IGkzFE/72UtLpMeB1N62Pwf7Zxax/xK4f/D9pilE4rZeetABBV2aUoAWwiZJw+ncza8QLiWeg== X-Received: by 2002:a17:903:124d:b0:21a:8dec:e57a with SMTP id d9443c01a7336-21c35619607mr540586485ad.48.1737964990824; Mon, 27 Jan 2025 00:03:10 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:566d:6152:c049:8d3a]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-21da3d9c9f2sm57195075ad.42.2025.01.27.00.03.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Jan 2025 00:03:10 -0800 (PST) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim , Johannes Weiner , Yosry Ahmed , Nhat Pham Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky Subject: [RFC PATCH 1/6] zram: deffer slot free notification Date: Mon, 27 Jan 2025 16:59:26 +0900 Message-ID: <20250127080254.1302026-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <20250127080254.1302026-1-senozhatsky@chromium.org> References: <20250127080254.1302026-1-senozhatsky@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As of this moment ->swap_slot_free_notify is called from atomic section (under spin-lock) which makes it impossible to make zsmalloc fully preemptible. Deffer slot-free to a non-atomic context. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 66 +++++++++++++++++++++++++++++++++-- drivers/block/zram/zram_drv.h | 4 +++ 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index ad3e8885b0d2..9c72beb86ab0 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -2315,9 +2315,52 @@ static void zram_submit_bio(struct bio *bio) } } =20 +static void async_slot_free(struct work_struct *work) +{ + struct zram *zram =3D container_of(work, struct zram, slot_free_work); + + spin_lock(&zram->slot_free_lock); + while (!list_empty(&zram->slot_free_list)) { + struct zram_pp_slot *pps; + + pps =3D list_first_entry(&zram->slot_free_list, + struct zram_pp_slot, + entry); + list_del_init(&pps->entry); + spin_unlock(&zram->slot_free_lock); + + zram_slot_write_lock(zram, pps->index); + if (zram_test_flag(zram, pps->index, ZRAM_PP_SLOT)) + zram_free_page(zram, pps->index); + zram_slot_write_unlock(zram, pps->index); + + kfree(pps); + spin_lock(&zram->slot_free_lock); + } + spin_unlock(&zram->slot_free_lock); +}; + +static void zram_kick_slot_free(struct zram *zram) +{ + schedule_work(&zram->slot_free_work); +} + +static void zram_flush_slot_free(struct zram *zram) +{ + flush_work(&zram->slot_free_work); +} + +static void zram_init_slot_free(struct zram *zram) +{ + spin_lock_init(&zram->slot_free_lock); + INIT_LIST_HEAD(&zram->slot_free_list); + INIT_WORK(&zram->slot_free_work, async_slot_free); +} + static void zram_slot_free_notify(struct block_device *bdev, - unsigned long index) + unsigned long index) { + struct zram_pp_slot *pps; struct zram *zram; =20 zram =3D bdev->bd_disk->private_data; @@ -2328,7 +2371,24 @@ static void zram_slot_free_notify(struct block_devic= e *bdev, return; } =20 - zram_free_page(zram, index); + if (zram_test_flag(zram, index, ZRAM_PP_SLOT)) + goto out; + + pps =3D kzalloc(sizeof(*pps), GFP_ATOMIC); + if (!pps) { + atomic64_inc(&zram->stats.miss_free); + goto out; + } + + INIT_LIST_HEAD(&pps->entry); + pps->index =3D index; + zram_set_flag(zram, index, ZRAM_PP_SLOT); + spin_lock(&zram->slot_free_lock); + list_add(&pps->entry, &zram->slot_free_list); + spin_unlock(&zram->slot_free_lock); + + zram_kick_slot_free(zram); +out: zram_slot_write_unlock(zram, index); } =20 @@ -2473,6 +2533,7 @@ static ssize_t reset_store(struct device *dev, =20 /* Make sure all the pending I/O are finished */ sync_blockdev(disk->part0); + zram_flush_slot_free(zram); zram_reset_device(zram); =20 mutex_lock(&disk->open_mutex); @@ -2618,6 +2679,7 @@ static int zram_add(void) atomic_set(&zram->pp_in_progress, 0); zram_comp_params_reset(zram); comp_algorithm_set(zram, ZRAM_PRIMARY_COMP, default_compressor); + zram_init_slot_free(zram); =20 /* Actual capacity set using sysfs (/sys/block/zram/disksize */ set_capacity(zram->disk, 0); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index b7e250d6fa02..27ca269f4a4e 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -134,5 +134,9 @@ struct zram { struct dentry *debugfs_dir; #endif atomic_t pp_in_progress; + + spinlock_t slot_free_lock; + struct list_head slot_free_list; + struct work_struct slot_free_work; }; #endif --=20 2.48.1.262.g85cc9f2d1e-goog