Skip to content

Commit

Permalink
Merge ../zfs into adam105
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdmoss committed Jul 30, 2024
2 parents bd9281d + d4b5517 commit 9b13ed2
Show file tree
Hide file tree
Showing 23 changed files with 144 additions and 79 deletions.
1 change: 1 addition & 0 deletions include/os/freebsd/spl/sys/kmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ MALLOC_DECLARE(M_SOLARIS);
#define KM_NOSLEEP M_NOWAIT
#define KM_NORMALPRI 0
#define KMC_NODEBUG UMA_ZONE_NODUMP
#define KMC_RECLAIMABLE 0x0

typedef struct vmem vmem_t;

Expand Down
5 changes: 2 additions & 3 deletions include/os/linux/spl/sys/kmem_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef enum kmc_bit {
KMC_BIT_TOTAL = 18, /* Proc handler helper bit */
KMC_BIT_ALLOC = 19, /* Proc handler helper bit */
KMC_BIT_MAX = 20, /* Proc handler helper bit */
KMC_BIT_RECLAIMABLE = 21, /* Can be freed by shrinker */
} kmc_bit_t;

/* kmem move callback return values */
Expand All @@ -66,9 +67,7 @@ typedef enum kmem_cbrc {
#define KMC_TOTAL (1 << KMC_BIT_TOTAL)
#define KMC_ALLOC (1 << KMC_BIT_ALLOC)
#define KMC_MAX (1 << KMC_BIT_MAX)

#define KMC_REAP_CHUNK INT_MAX
#define KMC_DEFAULT_SEEKS 1
#define KMC_RECLAIMABLE (1 << KMC_BIT_RECLAIMABLE)

extern struct list_head spl_kmem_cache_list;
extern struct rw_semaphore spl_kmem_cache_sem;
Expand Down
16 changes: 15 additions & 1 deletion include/sys/dbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,15 @@ typedef struct dmu_buf_impl {
struct objset *db_objset;

/*
* handle to safely access the dnode we belong to (NULL when evicted)
* Handle to safely access the dnode we belong to (NULL when evicted)
* if dnode_move() is used on the platform, or just dnode otherwise.
*/
#if !defined(__linux__) && !defined(__FreeBSD__)
#define USE_DNODE_HANDLE 1
struct dnode_handle *db_dnode_handle;
#else
struct dnode *db_dnode;
#endif

/*
* our parent buffer; if the dnode points to us directly,
Expand Down Expand Up @@ -417,11 +423,19 @@ void dbuf_stats_destroy(void);
int dbuf_dnode_findbp(dnode_t *dn, uint64_t level, uint64_t blkid,
blkptr_t *bp, uint16_t *datablkszsec, uint8_t *indblkshift);

#ifdef USE_DNODE_HANDLE
#define DB_DNODE(_db) ((_db)->db_dnode_handle->dnh_dnode)
#define DB_DNODE_LOCK(_db) ((_db)->db_dnode_handle->dnh_zrlock)
#define DB_DNODE_ENTER(_db) (zrl_add(&DB_DNODE_LOCK(_db)))
#define DB_DNODE_EXIT(_db) (zrl_remove(&DB_DNODE_LOCK(_db)))
#define DB_DNODE_HELD(_db) (!zrl_is_zero(&DB_DNODE_LOCK(_db)))
#else
#define DB_DNODE(_db) ((_db)->db_dnode)
#define DB_DNODE_LOCK(_db)
#define DB_DNODE_ENTER(_db)
#define DB_DNODE_EXIT(_db)
#define DB_DNODE_HELD(_db) (B_TRUE)
#endif

void dbuf_init(void);
void dbuf_fini(void);
Expand Down
5 changes: 5 additions & 0 deletions include/sys/dnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ struct dnode {

/* holds prefetch structure */
struct zfetch dn_zfetch;

/* Not in dn_phys, but should be. set it after taking a hold */
dmu_object_type_t dn_storage_type; /* type for storage class */
};

/*
Expand Down Expand Up @@ -462,6 +465,8 @@ void dnode_evict_dbufs(dnode_t *dn);
void dnode_evict_bonus(dnode_t *dn);
void dnode_free_interior_slots(dnode_t *dn);

void dnode_set_storage_type(dnode_t *dn, dmu_object_type_t type);

#define DNODE_IS_DIRTY(_dn) \
((_dn)->dn_dirty_txg >= spa_syncing_txg((_dn)->dn_objset->os_spa))

Expand Down
3 changes: 1 addition & 2 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1049,8 +1049,7 @@ extern metaslab_class_t *spa_log_class(spa_t *spa);
extern metaslab_class_t *spa_embedded_log_class(spa_t *spa);
extern metaslab_class_t *spa_special_class(spa_t *spa);
extern metaslab_class_t *spa_dedup_class(spa_t *spa);
extern metaslab_class_t *spa_preferred_class(spa_t *spa, uint64_t size,
dmu_object_type_t objtype, uint_t level, uint_t special_smallblk);
extern metaslab_class_t *spa_preferred_class(spa_t *spa, const zio_t *zio);
extern boolean_t spa_special_has_ddt(spa_t *spa);

extern void spa_evicting_os_register(spa_t *, objset_t *os);
Expand Down
1 change: 1 addition & 0 deletions include/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ void procfs_list_add(procfs_list_t *procfs_list, void *p);
#define KM_NORMALPRI 0 /* not needed with UMEM_DEFAULT */
#define KMC_NODEBUG UMC_NODEBUG
#define KMC_KVMEM 0x0
#define KMC_RECLAIMABLE 0x0
#define kmem_alloc(_s, _f) umem_alloc(_s, _f)
#define kmem_zalloc(_s, _f) umem_zalloc(_s, _f)
#define kmem_free(_b, _s) umem_free(_b, _s)
Expand Down
1 change: 1 addition & 0 deletions include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ typedef struct zio_prop {
uint8_t zp_iv[ZIO_DATA_IV_LEN];
uint8_t zp_mac[ZIO_DATA_MAC_LEN];
uint32_t zp_zpl_smallblk;
dmu_object_type_t zp_storage_type;
} zio_prop_t;

typedef struct zio_cksum_report zio_cksum_report_t;
Expand Down
2 changes: 1 addition & 1 deletion module/os/freebsd/zfs/abd_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ void
abd_init(void)
{
abd_chunk_cache = kmem_cache_create("abd_chunk", PAGE_SIZE, 0,
NULL, NULL, NULL, NULL, 0, KMC_NODEBUG);
NULL, NULL, NULL, NULL, 0, KMC_NODEBUG | KMC_RECLAIMABLE);

wmsum_init(&abd_sums.abdstat_struct_size, 0);
wmsum_init(&abd_sums.abdstat_scatter_cnt, 0);
Expand Down
2 changes: 1 addition & 1 deletion module/os/freebsd/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ zfs_znode_init(void)
ASSERT3P(znode_cache, ==, NULL);
znode_cache = kmem_cache_create("zfs_znode_cache",
sizeof (znode_t), 0, zfs_znode_cache_constructor,
zfs_znode_cache_destructor, NULL, NULL, NULL, 0);
zfs_znode_cache_destructor, NULL, NULL, NULL, KMC_RECLAIMABLE);
}

static znode_t *
Expand Down
8 changes: 8 additions & 0 deletions module/os/linux/spl/spl-kmem-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ kv_alloc(spl_kmem_cache_t *skc, int size, int flags)
gfp_t lflags = kmem_flags_convert(flags);
void *ptr;

if (skc->skc_flags & KMC_RECLAIMABLE)
lflags |= __GFP_RECLAIMABLE;
ptr = spl_vmalloc(size, lflags | __GFP_HIGHMEM);

/* Resulting allocated memory will be page aligned */
Expand Down Expand Up @@ -424,6 +426,8 @@ spl_emergency_alloc(spl_kmem_cache_t *skc, int flags, void **obj)
if (!empty)
return (-EEXIST);

if (skc->skc_flags & KMC_RECLAIMABLE)
lflags |= __GFP_RECLAIMABLE;
ske = kmalloc(sizeof (*ske), lflags);
if (ske == NULL)
return (-ENOMEM);
Expand Down Expand Up @@ -663,6 +667,7 @@ spl_magazine_destroy(spl_kmem_cache_t *skc)
* KMC_KVMEM Force kvmem backed SPL cache
* KMC_SLAB Force Linux slab backed cache
* KMC_NODEBUG Disable debugging (unsupported)
* KMC_RECLAIMABLE Memory can be freed under pressure
*/
spl_kmem_cache_t *
spl_kmem_cache_create(const char *name, size_t size, size_t align,
Expand Down Expand Up @@ -780,6 +785,9 @@ spl_kmem_cache_create(const char *name, size_t size, size_t align,
if (size > spl_kmem_cache_slab_limit)
goto out;

if (skc->skc_flags & KMC_RECLAIMABLE)
slabflags |= SLAB_RECLAIM_ACCOUNT;

#if defined(SLAB_USERCOPY)
/*
* Required for PAX-enabled kernels if the slab is to be
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/spl/spl-zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ spl_zlib_init(void)
zlib_workspace_cache = kmem_cache_create(
"spl_zlib_workspace_cache",
size, 0, NULL, NULL, NULL, NULL, NULL,
KMC_KVMEM);
KMC_KVMEM | KMC_RECLAIMABLE);
if (!zlib_workspace_cache)
return (-ENOMEM);

Expand Down
6 changes: 3 additions & 3 deletions module/os/linux/zfs/abd_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ abd_alloc_chunks(abd_t *abd, size_t size)
struct sg_table table;
struct scatterlist *sg;
struct page *page, *tmp_page = NULL;
gfp_t gfp = __GFP_NOWARN | GFP_NOIO;
gfp_t gfp = __GFP_RECLAIMABLE | __GFP_NOWARN | GFP_NOIO;
gfp_t gfp_comp = (gfp | __GFP_NORETRY | __GFP_COMP) & ~__GFP_RECLAIM;
unsigned int max_order = MIN(zfs_abd_scatter_max_order,
ABD_MAX_ORDER - 1);
Expand Down Expand Up @@ -403,7 +403,7 @@ abd_alloc_chunks(abd_t *abd, size_t size)
struct scatterlist *sg = NULL;
struct sg_table table;
struct page *page;
gfp_t gfp = __GFP_NOWARN | GFP_NOIO;
gfp_t gfp = __GFP_RECLAIMABLE | __GFP_NOWARN | GFP_NOIO;
int nr_pages = abd_chunkcnt_for_bytes(size);
int i = 0;

Expand Down Expand Up @@ -762,7 +762,7 @@ abd_init(void)
int i;

abd_cache = kmem_cache_create("abd_t", sizeof (abd_t),
0, NULL, NULL, NULL, NULL, NULL, 0);
0, NULL, NULL, NULL, NULL, NULL, KMC_RECLAIMABLE);

wmsum_init(&abd_sums.abdstat_struct_size, 0);
wmsum_init(&abd_sums.abdstat_linear_cnt, 0);
Expand Down
3 changes: 2 additions & 1 deletion module/os/linux/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ zfs_znode_init(void)
ASSERT(znode_cache == NULL);
znode_cache = kmem_cache_create("zfs_znode_cache",
sizeof (znode_t), 0, zfs_znode_cache_constructor,
zfs_znode_cache_destructor, NULL, NULL, NULL, KMC_SLAB);
zfs_znode_cache_destructor, NULL, NULL, NULL,
KMC_SLAB | KMC_RECLAIMABLE);

ASSERT(znode_hold_cache == NULL);
znode_hold_cache = kmem_cache_create("zfs_znode_hold_cache",
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ buf_init(void)
}

hdr_full_cache = kmem_cache_create("arc_buf_hdr_t_full", HDR_FULL_SIZE,
0, hdr_full_cons, hdr_full_dest, NULL, NULL, NULL, 0);
0, hdr_full_cons, hdr_full_dest, NULL, NULL, NULL, KMC_RECLAIMABLE);
hdr_l2only_cache = kmem_cache_create("arc_buf_hdr_t_l2only",
HDR_L2ONLY_SIZE, 0, hdr_l2only_cons, hdr_l2only_dest, NULL,
NULL, NULL, 0);
Expand Down
19 changes: 12 additions & 7 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3103,7 +3103,11 @@ dbuf_destroy(dmu_buf_impl_t *db)
*/
mutex_enter(&dn->dn_mtx);
dnode_rele_and_unlock(dn, db, B_TRUE);
#ifdef USE_DNODE_HANDLE
db->db_dnode_handle = NULL;
#else
db->db_dnode = NULL;
#endif

dbuf_hash_remove(db);
} else {
Expand Down Expand Up @@ -3252,7 +3256,11 @@ dbuf_create(dnode_t *dn, uint8_t level, uint64_t blkid,
db->db_level = level;
db->db_blkid = blkid;
db->db_dirtycnt = 0;
#ifdef USE_DNODE_HANDLE
db->db_dnode_handle = dn->dn_handle;
#else
db->db_dnode = dn;
#endif
db->db_parent = parent;
db->db_blkptr = blkptr;
db->db_hash = hash;
Expand Down Expand Up @@ -4390,7 +4398,7 @@ dbuf_lightweight_bp(dbuf_dirty_record_t *dr)
dmu_buf_impl_t *parent_db = dr->dr_parent->dr_dbuf;
int epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
VERIFY3U(parent_db->db_level, ==, 1);
VERIFY3P(parent_db->db_dnode_handle->dnh_dnode, ==, dn);
VERIFY3P(DB_DNODE(parent_db), ==, dn);
VERIFY3U(dr->dt.dll.dr_blkid >> epbs, ==, parent_db->db_blkid);
blkptr_t *bp = parent_db->db.db_data;
return (&bp[dr->dt.dll.dr_blkid & ((1 << epbs) - 1)]);
Expand Down Expand Up @@ -4813,14 +4821,13 @@ dbuf_write_children_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
{
(void) zio, (void) buf;
dmu_buf_impl_t *db = vdb;
dnode_t *dn;
blkptr_t *bp;
unsigned int epbs, i;

ASSERT3U(db->db_level, >, 0);
DB_DNODE_ENTER(db);
dn = DB_DNODE(db);
epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
epbs = DB_DNODE(db)->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
DB_DNODE_EXIT(db);
ASSERT3U(epbs, <, 31);

/* Determine if all our children are holes */
Expand All @@ -4843,7 +4850,6 @@ dbuf_write_children_ready(zio_t *zio, arc_buf_t *buf, void *vdb)
memset(db->db.db_data, 0, db->db.db_size);
rw_exit(&db->db_rwlock);
}
DB_DNODE_EXIT(db);
}

static void
Expand Down Expand Up @@ -5062,8 +5068,7 @@ dbuf_remap(dnode_t *dn, dmu_buf_impl_t *db, dmu_tx_t *tx)
}
} else if (db->db.db_object == DMU_META_DNODE_OBJECT) {
dnode_phys_t *dnp = db->db.db_data;
ASSERT3U(db->db_dnode_handle->dnh_dnode->dn_type, ==,
DMU_OT_DNODE);
ASSERT3U(dn->dn_type, ==, DMU_OT_DNODE);
for (int i = 0; i < db->db.db_size >> DNODE_SHIFT;
i += dnp[i].dn_extra_slots + 1) {
for (int j = 0; j < dnp[i].dn_nblkptr; j++) {
Expand Down
Loading

0 comments on commit 9b13ed2

Please sign in to comment.