Commit 8c7f6e9b authored by Nicholas Bellinger's avatar Nicholas Bellinger

target: Fall back to vzalloc upon ->sess_cmd_map kzalloc failure

This patch changes transport_alloc_session_tags() to fall back to
use vzalloc when kzalloc fails for big tag_num that end up generating
larger order allocations.

Also use is_vmalloc_addr() in transport_alloc_session_tags() failure
path, and normal transport_free_session() path to determine when
vfree() needs to be called instead of kfree().

v2 changes:
  - Use  __GFP_NOWARN | __GFP_REPEAT for sess_cmd_map kzalloc (mst)

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Asias He <asias@redhat.com>
Cc: Kent Overstreet <kmo@daterainc.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 4a47d3a1
...@@ -236,17 +236,24 @@ int transport_alloc_session_tags(struct se_session *se_sess, ...@@ -236,17 +236,24 @@ int transport_alloc_session_tags(struct se_session *se_sess,
{ {
int rc; int rc;
se_sess->sess_cmd_map = kzalloc(tag_num * tag_size, GFP_KERNEL); se_sess->sess_cmd_map = kzalloc(tag_num * tag_size,
GFP_KERNEL | __GFP_NOWARN | __GFP_REPEAT);
if (!se_sess->sess_cmd_map) { if (!se_sess->sess_cmd_map) {
pr_err("Unable to allocate se_sess->sess_cmd_map\n"); se_sess->sess_cmd_map = vzalloc(tag_num * tag_size);
return -ENOMEM; if (!se_sess->sess_cmd_map) {
pr_err("Unable to allocate se_sess->sess_cmd_map\n");
return -ENOMEM;
}
} }
rc = percpu_ida_init(&se_sess->sess_tag_pool, tag_num); rc = percpu_ida_init(&se_sess->sess_tag_pool, tag_num);
if (rc < 0) { if (rc < 0) {
pr_err("Unable to init se_sess->sess_tag_pool," pr_err("Unable to init se_sess->sess_tag_pool,"
" tag_num: %u\n", tag_num); " tag_num: %u\n", tag_num);
kfree(se_sess->sess_cmd_map); if (is_vmalloc_addr(se_sess->sess_cmd_map))
vfree(se_sess->sess_cmd_map);
else
kfree(se_sess->sess_cmd_map);
se_sess->sess_cmd_map = NULL; se_sess->sess_cmd_map = NULL;
return -ENOMEM; return -ENOMEM;
} }
...@@ -412,7 +419,10 @@ void transport_free_session(struct se_session *se_sess) ...@@ -412,7 +419,10 @@ void transport_free_session(struct se_session *se_sess)
{ {
if (se_sess->sess_cmd_map) { if (se_sess->sess_cmd_map) {
percpu_ida_destroy(&se_sess->sess_tag_pool); percpu_ida_destroy(&se_sess->sess_tag_pool);
kfree(se_sess->sess_cmd_map); if (is_vmalloc_addr(se_sess->sess_cmd_map))
vfree(se_sess->sess_cmd_map);
else
kfree(se_sess->sess_cmd_map);
} }
kmem_cache_free(se_sess_cache, se_sess); kmem_cache_free(se_sess_cache, se_sess);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment